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()返回的是两个字符串的差值。

posted @ 2016-05-02 16:08  冷漠脸  阅读(198)  评论(0编辑  收藏  举报