|
- Java String implements Comparable interface and it has two variants of compareTo() methods.
-
compareTo(String another String) method compares the String object with the String argument passed lexicographically.
-
If String object precedes the argument passed, it returns negative integer and if String object follows the argument String passed, it returns positive integer.
-
It returns zero when both the String have same value, in this case equals (String str) method will also return true.
-
compare ToIgnoreCase (String str): This method is similar to the first one, except that it ignores the case.
-
It uses String CASE_INSENSITIVE_ORDER Comparator for case insensitive comparison.
- If the value is zero thenequalsIgnoreCase(String str) will also return true.
|