CompareTo
public class TestCompareTo {
public static void main(String[] args){
Integer a = new Integer(12);
Integer b = new Integer(15);
Integer c = new Integer(5);
String d = new String("g");
String e = new String("k");
String f = new String("a");
System.out.println(a.compareTo(b));
System.out.println(a.compareTo(c));
System.out.println();
System.out.println(d.compareTo(e));
System.out.println(d.compareTo(f));
}
}
-1
1
-4
6
Integer使用compareTo()返回的是-1,0 1 而String使用comareTo()返回的是两个字符串的差值。