Advertisements
Advertisements
Question
Differentiate between compareTo() and equals().
Distinguish Between
Solution
S. No. | compareTo() | equals() |
1. | This function analyses whether a string is equal to, more significant than, or smaller than another string. | This function in the String class checks if two strings are identical. (The equals() function handles upper and lower case characters differently). |
2. | It produces an integer-type value. (The function returns 0 if both strings are equal, a negative number if the first string is smaller, and a positive value if the first string is larger). | It returns a boolean value (true or false). |
shaalaa.com
Is there an error in this question or solution?