2024-11-23 08:25:35
java的String类中有一个compareTo的方法。
public class test {
public static void main(String[] args) {
String a = "abb";
String b = "abc";
System.out.println(a.compareTo(b));
String a1 = "abc";
String b1 = "abc";
System.out.println(a1.compareTo(b1));
String a2 = "abd";
String b2 = "abc";
System.out.println(a2.compareTo(b2));
}
}
小于输出负数,相等输出0, 大于输出正数
2024-11-23 09:33:10
2024-11-23 08:59:33
2024-11-23 10:17:44