1 //前提为a、b均不能为null 2 if(a.compareTo(b) == -1){ 3 System.out.println("a小于b"); 4 } 5 6 if(a.compareTo(b) == 0){ 7 System.out.println("a等于b"); 8 } 9 10 if(a.compareTo(b) == 1){ 11 System.out.println("a大于b"); 12 } 13 14 if(a.compareTo(b) > -1){ 15 System.out.println("a大于等于b"); 16 } 17 18 if(a.compareTo(b) < 1){ 19 System.out.println("a小于等于b"); 20 }