1、boolean equals(Object obj); 比较字符串的内容是否相同,区分大小写
2、boolean equalsIgonreCase(String str): 比较字符串的内容是否相同,忽略大小写
private static void demo1() {
String s1 = "fage";
String s2 = "fage";
String s3 = "Fage";
System.out.println(s1.equals(s2)); //结果==true
System.out.println(s2.equals(s3)); //区分大小写 结果==false
System.out.println("--------------------------");
System.out.println(s1.equalsIgnoreCase(s2)); //结果==true
System.out.println(s2.equalsIgnoreCase(s3)); //不区分大小写 结果==true
}
3、boolean contains(String str): 判断大字符串中是否含有小字符串
4、boolean startsWith(String str): 判断字符串是否以某个指定的字符串开头
5、boolean endWith(String str): 判断字符串是否以某个指定字符串结尾
private static void demo2() {
String s1 = "我是一个superman,哈哈";
String s2 = "superman";
String s3 = "NOsuperman";
String s4 = "我是一个";
String s5 = "哈哈";
//判断大字符串中是否含有小字符串
System.out.println(s1.contains(s2)); //结果==true
System.out.println(s1.contains(s3)); //结果==false
//判断字符串是否以某个指定的字符串开头
System.out.println(s1.startsWith(s4)); //结果==true
System.out.println(s1.startsWith(s5)); //结果==false
// 判断字符串是否以某个指定字符串结尾
System.out.println(s1.endsWith(s4)); //结果==false
System.out.println(s1.endsWith(s5)); //结果==true
}
6、boolean isEmpty(): 判断字符串是否为空
private static void demo3() {
String s1 = "fage";
String s2 = "";
System.out.println(s1.isEmpty()); //结果==false
System.out.println(s2.isEmpty()); //结果==true
}