Check out example codes for "compareto method java". It will help you in understanding the concepts better.

Code Example 1

String.compareTo();
// will return the difference of the Strings unicode placement

Code Example 2

String str1 = "Negan";  
String str2 = ""; //empty string

//it would return the length of str1 in positive number
str1.compareTo(str2); // 5

//it would return the length of str1 in negative number
str2.compareTo(str1); //-5

Learn ReactJs, React Native from akashmittal.com