package com.shujia.day11;
/*
String类中的判断功能:
boolean equals(Object obj) String类中的equals是重写父类Object中的equals方法,比较的是内容
boolean equalsIgnoreCase(String str) 忽略大小写比较字符串内容
boolean contains(String str) 判断大字符串中是否有小字符串
boolean startsWith(String str) 判断字符串是否以指定字符串开头
boolean endsWith(String str) 判断字符串是否以指定字符串结尾
boolean isEmpty() 判断字符串是否为空字符串
*/
public class StringDemo4 {
public static void main(String[] args) {
String s1 = "hello";
String s2 = "HelLO";
//boolean equals(Object obj)
boolean b1 = s1.equals(s2); // String类中的equals是重写父类Object中的equals方法,比较的是内容
System.out.println(b1);
//boolean equalsIgnoreCase(String str)
boolean b2 = s1.equalsIgnoreCase(s2); // 忽略大小写比较字符串内容
System.out.println(b2);
//boolean contains(String str) // 判断大字符串中是否有小字符串
String s3 = "魏一民真shujia帅";
String s4 = "shujia666";
boolean b3 = s3.contains(s4);
System.out.println(b3);
//boolean startsWith(String str) // 判断字符串是否以指定字符串开头
boolean b4 = s3.startsWith("魏一");
System.out.println(b4);
//boolean endsWith(String str) // 判断字符串是否以指定字符串结尾
boolean b5 = s3.endsWith("帅");
System.out.println(b5);
// boolean isEmpty() 判断字符串是否为空字符串
boolean b6 = s3.isEmpty();
System.out.println(b6);
s3 = "";
System.out.println(s3.isEmpty());
// s3 = null;
// System.out.println(s3.isEmpty()); // NullPointerException
}
}
标签:String,s3,System,boolean,day11,字符串,类中,out
From: https://www.cnblogs.com/qiwei-bigdata/p/18349681