+ 10
The string compareTo() method compares the given string with current string lexicographically (length wise or character wise). It compares strings on the basis of Unicode value of each character in the strings. Your code : "cable".compareTo("cadet") has equal lengths, so it would return -2 as the output because b < d (as d exceeds b by 2, in unicodes as well.)
27th Sep 2017, 3:26 PM
Dev
Dev - avatar