Computer Applications
Differentiate between equals() and compareTo().
Java String Handling
6 Likes
Answer
| equals() | compareTo() |
|---|---|
| equals() checks if contents of two strings are same or not. | compareTo() compares two strings lexicographically. |
| The result is true if the contents are same otherwise it is false. | The result is a negative, positive or zero integer value depending on whether the String object precedes, follows or is equal to the String argument. |
Answered By
4 Likes