文章詳情頁
JAVA中文比較問題的分析解決
瀏覽:136日期:2024-06-11 16:52:57
內(nèi)容: Java的中文問題由來已久,前不久筆者需要做內(nèi)存中的中文比較排序,對字符串進行GBK或者GB2312編碼以后,使用String.compareTo方法仍然不能得到正確結(jié)果。因此,懷著懷疑的態(tài)度,對JDK中String類的源代碼做了一翻探究。(作者使用JDK為1.3.1版本) 以下是String.java中compareTo的源代碼,請注意其中的注釋: public class String { … public int compareTo(String anotherString) { int len1 = count; int len2 = anotherString.count; //n為兩個字符串長度的最小者 int n = Math.min(len1, len2); //獲取字符數(shù)組 char v1[] = value; char v2[] = anotherString.value; //取偏依位置 /** The offset is the first index of the storage that is used. */ //offset 是第一個存儲索引 int i = offset; int j = anotherString.offset; //如果i == j //這里可能是判斷取同一內(nèi)存中兩個字符串的情景。。。 // A
標簽:
Java
上一條:JSWDK配置詳解下一條:刪除java的注釋信息
相關(guān)文章:
1. 解決Python數(shù)據(jù)可視化中文部分顯示方塊問題2. Java FTP客戶端類庫比較(一)3. windows服務(wù)器使用IIS時thinkphp搜索中文無效問題4. ajax post下載flask文件流以及中文文件名問題5. ant design vue datepicker日期選擇器中文化操作6. PHP網(wǎng)站開發(fā)遇到的中文編碼7. java進行數(shù)據(jù)的比較的實例方法8. Python如何解決secure_filename對中文不支持問題9. Python接口測試結(jié)果集實現(xiàn)封裝比較10. PHP 開發(fā)中的中文編碼問題
排行榜
