1>
 public int compareTo(String anotherString) {
int len1 = count;
int len2 = anotherString.count;
int n = Math.min(len1, len2);
char v1[] = value;
char v2[] = anotherString.value;
int i = offset;
int j = anotherString.offset; if (i == j) {
    int k = i;
    int lim = n + i;
    while (k < lim) {
char c1 = v1[k];
char c2 = v2[k];
if (c1 != c2) {
    return c1 - c2;
}
k++;
    }
} else {
    while (n-- != 0) {
char c1 = v1[i++];
char c2 = v2[j++];
if (c1 != c2) {
    return c1 - c2;
}
    }
}
return len1 - len2;
    }

解决方案 »

  1.   

    我觉得是这样吧
    public int compareTo(String anotherString) {    return   this.toCharArray().lenth-anotherString.toCharArray().lenth;}
      

  2.   

    关于System.gc(),好多资料是说调用jvm的垃圾回收功能
    但好象这个方法并不能保证jvm执行垃圾回收,
    至于不回收的结果是什么?那就是什么结果也没有,jvm本来该什么时候回收的还是什么时候回收吧
      

  3.   

    public class Test
    {
    public static void main(String[] args)
    {
    String s1="ab";
    System.out.println(s1.compareTo("ab"));//相等0
    System.out.println(s1.compareTo("a"));//大于就1,aa也大于
    System.out.println(s1.compareTo("b"));//-1按照字典排列来比较的?
    }
    }
      

  4.   

    this.charAt(k)-anotherString.charAt(k)
     
    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()
      

  5.   

    java有自动垃圾回收机制,可以不用自已去管理内存垃圾的。