This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Long object comparison Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Long object comparison" Watch "Long object comparison" New topic
Author

Long object comparison

Bushra Binte
Ranch Hand

Joined: Nov 07, 2006
Posts: 60
Hi,I have to compare two long objects.I need to check if the values stored in the two Long objects is the same.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
As for every other well-implemented Java object, you normally use Object#equals() for this.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

Please take the time to choose the correct forum for your posts. This forum is for questions on JSF.

For more information, please read this.

This post has been moved to a more appropriate forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37897
    
  22
Agree that the equals method is the simplest way to do it, and most probably the best. By long objects, you obviously mean Long objects.
As an alternative you can get the value as a primitive with the longValue() method. Or use the compareTo() method and see whether the result is 0.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Long object comparison
 
Similar Threads
Amul (an indian milk products firm) coming to Walmart
Passing value to the wrapper class
Using 'volatile'