This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Long object comparison  RSS feed

 
Bushra Binte
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for every other well-implemented Java object, you normally use Object#equals() for this.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Campbell Ritchie
Marshal
Posts: 55799
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!