文章詳情頁
JAVA中文比較問題的分析解決
瀏覽:89日期:2024-06-11 16:52:57
內容: Java的中文問題由來已久,前不久筆者需要做內存中的中文比較排序,對字符串進行GBK或者GB2312編碼以后,使用String.compareTo方法仍然不能得到正確結果。因此,懷著懷疑的態度,對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); //獲取字符數組 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 //這里可能是判斷取同一內存中兩個字符串的情景。。。 // A
標簽:
Java
上一條:JSWDK配置詳解下一條:刪除java的注釋信息
相關文章:
排行榜
