File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Long object comparison" Watch "Long object comparison" New topic

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

Joined: Jan 10, 2002
Posts: 63870

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] [About Bear] [Books by Bear]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46424
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.
I agree. Here's the link:
subject: Long object comparison
It's not a secret anymore!