wood burning stoves 2.0*
The moose likes Java in General and the fly likes interface Comparable vs. equals() method 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 » Java in General
Bookmark "interface Comparable vs. equals() method" Watch "interface Comparable vs. equals() method" New topic
Author

interface Comparable vs. equals() method

James Brooks
Gunslinger
Ranch Hand

Joined: Aug 17, 2006
Posts: 165
Sorry, same question, but slightly different topic, so thought I'd start a new thread. Is one better than the other for any reason? My book does not offer an opinion. Thanks!


Hello. My name is Inigo Montoya. You killed my father. Prepare to die.
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Comparable is an interface:public int compareTo(T o);

You write that when you write some class, or you assure that it is present in some class you are going to store in an ordered collection.

the .equals method is used where == won't work, the double equals (==) simple gives the reference address of an object, it will work on primitives such as integer, double and whatever. It will not work on anything that is an instance of a class, at least on in the traditional sense, instanceof is often used where one would initially consider ==


"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: interface Comparable vs. equals() method