the CompareTo method in Java, returns the difference between the ASC codes of the previous two strings participating in the comparison, and the following set of code String a= "A", b= "B"; System.out.println (A.COMPARETO.B); the output is 1; if a= "a", b= "a" outputs 0; if a= "B", b= "a" is output 1; a single character is so compared, what if the string is longer?? If a= "AB", b= "B", then output-1, if a= "abcdef", b= "B" is output-1; that is
, if the first letter of two string is different, then the method returns the first letter of the ASC code difference , if the first letter is the same?? If a= "AB", b= "a", Output 1, if a= "abcdef", b= "a" output 5, if a= "abcdef", b= "abc" Output 3, if a= "abcdef", b= "Ace" output-1;
the two strings participating in the comparison if the first character is the same, Compares the next character until it is different, returns the ASC code difference of the different character, if the two string is not the same length, and the character that can participate in the comparison is exactly the same, the length difference of the two string is returned.
The use of CompareTo in Java.