int n1="This".compareToIgnoreCase("tHe"); int n2="JAVA".compareToIgnoreCase("javaline") int n3="Java".compareToIgnoreCase("Javits")
The result is n1=4,n2=-4,n3=-8,
Why is this? The reason is this:
n1: Comparing "This" with "tHe", starting from the third character, i is 4 larger than e.
n2: The first four characters are the same,
If there is no index position at which they differ, then the shorter string lexicographically precedes the longer string. In this case, compareTo returns the difference of the lengths of the strings -- that is, the value:
this.length()-anotherString.length()
n3: Same as n1
【Related recommendations】
1. Special recommendation:"php Programmer Toolbox" V0.1 version download
3. Detailed introduction to compareToIgnoreCase() method
4.compareToIgnoreCase() compares two strings without case sensitivity
5.Java classic string comparison method: compareToIgnoreCase()
6.Go deeper Learn the difference between compareTo and comparetoIgnorecase
The above is the detailed content of Detailed explanation of the principle of return value of compareToIgnoreCase. For more information, please follow other related articles on the PHP Chinese website!