// 按字典顺序比较两个字符串
String s1 = "hello";
String s2 = "aello";
String s3 = "mello";
String s4 = "hello";
String s5 = "Hello";
//System.out.println('m'+1);//109
System.out.println(s1.compareTo(s2));// 7
System.out.println(s1.compareTo(s3));// -5
System.out.println(s1.compareTo(s4));// 0
System.out.println(s1.compareTo(s5));//32
这是按字典顺序比较2个字符串,compare代表s1怎么和s2进行比较呢? |
|