详解compareToIgnoreCase的返回值的原理

Y2J
Y2J 原创
2017-05-17 10:31:45 1971浏览
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

【相关推荐】

1. 特别推荐“php程序员工具箱”V0.1版本下载

2. Java免费视频教程

3. 关于compareToIgnoreCase()方法的详细介绍

4.compareToIgnoreCase()不区分大小写比较两个字符串

5.Java经典字符串比较的方法:compareToIgnoreCase()

6.深入了解compareTo与comparetoIgnorecase之间的不同之处

以上就是详解compareToIgnoreCase的返回值的原理的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。