Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between compareTo and equals

 
Hui Ge
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between compareTo() and equals() in the String object? I am getting unexpected behaviour from these methods sometimes.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hui Ge
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
haha i noticed its my code that has errors not the method. Wrong speculation sorry
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not to worry. Its happened to the best of us.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic