aspose file tools*
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 Spring in Action this week in the Spring 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Difference between compareTo and equals