We introduced 3 methods for comparing strings.
- compareTo() - This method compares 2 strings and returns an integer value. If the 2 strings are exactly the same (including the case), a 0 will be returned. Else, the method will return the difference between the 2 strings. Using the return value, we can use it to help us sort strings. Refer to Lab 3 for an example, which I will also elaborate in class.
- equals() - This method also compares 2 strings but returns only the boolean values TRUE (when the strings are exactly the same) or FALSE (when the strings are not the same).
- equalsIgnoreCase() - This method does the same thing as equals() but ignores the case.
As usual, leave comments if you have questions.
No comments:
Post a Comment