No. | 方法名称 | 类型 | 描述 |
1 | public boolean equals(String anObject) | 普通 | 进行相等判断,区分大小写 |
2 | public boolean equalsIgnoreCase(String anotherString) | 普通 | 进行相等判断,不区分大小写 |
3 | public int compareTo(String anotherString) | 普通 | 判断两个字符串的大小(按照字符编码比较),此方法的返回值有如下三种操作: ·=0:表示要比较的两个字符串内容相同; ·>0:表示大于的结果。 ·<0:表示小于的结果。 |
======================================================
public class Demo {
public static void main(String[] args) {
String strA = "hello";
String strB = "hELLO";
System.out.println(strA.equals(strB));
System.out.println(strA.equalsIgnoreCase(strB));
}
}
=========================================================
public class Demo {
public static void main(String[] args) {
String strA = "hello";
String strB = "hELLO";
if (strA.compareTo(strB) > 0) {
System.out.println("大于");
}
}
}