跟大家講解下有關詳解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中文網