I was reading through my text book on Java Programming...It showed two class methods compareTo() and equals()...It seems to be that there is no difference between this two...Can someone pls clear me on this..Thank You!
mahes_ 0 Newbie Poster
Recommended Answers
Jump to PostI think you got it backwards.
compareTo() is used to compare Objects. It tests if THIS object is of the same type as the parameterized object. For instance,
String s = "t";
String s2 = "sdfsa";s.compareTo(s2); ///would be true
.equals() compares the contents of the …
Jump to PostcompareTo is used for sequential placement of Objects. It's mainly useful in conjunction with sorted collections.
equals is used to simply check for logical equality.In case of Strings compareTo will tell you which of the Strings being compared would come first in a case sensitive dictionary, equals would …
All 7 Replies
hooknc 1 Posting Whiz in Training
server_crash 64 Postaholic
hooknc commented: Thanks for catching my mistake. (b) +1
hooknc 1 Posting Whiz in Training
jwenting 1,905 duckman Team Colleague
Gargol 0 Light Poster
emil1816 0 Newbie Poster
rvntdhillon 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.