The compareTo() method is utilized to compare a string with another string.
Some points to remember:
- Here, If a string(S1) is same as string(S2) in comparison then this method returns zero.
- If S1 is less than S2 then a negative number is returned which is the difference of character value.
- If S1 is greater than S2 then a positive number is returned.
Method Definition: int compareTo(String another String)
Return Type: It returns an integer.
It returns zero as both the strings are same.
It returns a positive number as S1 is greater than S2 here.
It returns a negative number as S1 is less than S2 here.