Java String compareTo() is an inbuilt method that is used to compare two strings lexicographically where each character of both the strings are converted into a Unicode value. Java String compareTo() method is used for comparing the two strings lexicographically.

Each character of both the strings is converted into the Unicode value for comparison. If both strings are equal, then this method returns 0; otherwise, it returns the positive or negative value.

Java String compareTo
The compareTo() method returns three types of value, if both the string is equal, then it returns 0, if the first string is lexicographically greater than the second string then it returns a positive value, if the second string is lexicographically greater than the first one, then it returns a negative value.

#java #java string compareto

Java String compareTo Example | String compareTo() Function
2.20 GEEK