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 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!
compareTo(String anotherString) is used to compare if two Strings are equal and if they arn't …
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 …
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,889
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.