int n1="This".compareToIgnoreCase("tHe");
int n2="JAVA".compareToIgnoreCase("javaline")
int n3="Java".compareToIgnoreCase("Javits")
结果是n1=4,n2=-4,n3=-8,
这是为什么呢?原因是这样的:
n1:"This" 与 "tHe"比较,从第三个字符开始不同,i比e大4
n2:前面四个字符相同,
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:同n1
【相关推荐】