科技知识动态:详解compareToIgnoreCase的返回值的原理

导读跟大家讲解下有关详解compareToIgnoreCase的返回值的原理,相信小伙伴们对这个话题应该也很关注吧,现在就为小伙伴们说说详解compareToIgno

跟大家讲解下有关详解compareToIgnoreCase的返回值的原理,相信小伙伴们对这个话题应该也很关注吧,现在就为小伙伴们说说详解compareToIgnoreCase的返回值的原理,小编也收集到了有关详解compareToIgnoreCase的返回值的原理的相关资料,希望大家看到了会喜欢。

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大4n2:前面四个字符相同,

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中文网其它相关文章!

来源:php中文网

免责声明:本文由用户上传,如有侵权请联系删除!