This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Difference between compareTo and equals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference between compareTo and equals" Watch "Difference between compareTo and equals" New topic
Author

Difference between compareTo and equals

Hui Ge
Greenhorn

Joined: Mar 11, 2005
Posts: 25
What is the difference between compareTo() and equals() in the String object? I am getting unexpected behaviour from these methods sometimes.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What is your unexpected behaviour? compareTo(String string) in the String class behaves exactly like the equals(Object) method in the same class, the only difference being how it returns that these values are equal.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Hui Ge
Greenhorn

Joined: Mar 11, 2005
Posts: 25
haha i noticed its my code that has errors not the method. Wrong speculation sorry
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not to worry. Its happened to the best of us.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between compareTo and equals
 
Similar Threads
what is the difference between == and .equals() method????
diff b/w compare() and compareTo()
difference between equals() and == and compareTo()
all about comapring objects
loop trouble