String类的常用判断方法使用练习

选取了一些常用的判断方法进行了使用练习,后续跟新其他方法

package StringDemo;
// String类的判断方法解析
// 1:boolean equals();
// 判断字符串是否相等,区分大小写
// 2:boolean equalsIgnoreCase(String anotherString)
// 将此 String 与另一个 String 比较,不考虑大小写
// 3.boolean contains(CharSequence s)
// 判断字符串对象是否包含指定字符串 public class StringDemo { public static void main(String[] args) {
String sc="helloworld";
//1:boolean equals();
//判断字符串是否相等,区分大小写
System.out.println(sc.equals("HelloWorld"));
System.out.println("-----------------------"); // 2:boolean equalsIgnoreCase(String anotherString)
// 将此 String 与另一个 String 比较,不考虑大小写
System.out.println(sc.equalsIgnoreCase("helloworld"));
System.out.println("-----------------------"); //3.boolean contains(CharSequence s)
//判断字符串对象是否包含指定字符串(需连续)
System.out.println(sc.contains("hell"));
System.out.println("-----------------------"); // 4.boolean endsWith(String suffix)
//判断字符串是否以给定的字符结尾
System.out.println(sc.endsWith("d"));
System.out.println("-----------------------"); //5.boolean startsWith (String prefix)
//判断字符串是否以给定的字符串开头
System.out.println(sc.startsWith("hell"));
System.out.println("-----------------------"); //6.boolean isEmpty();
//判断字符串是否为空
System.out.println(sc.isEmpty());
System.out.println("-----------------------");
} }
上一篇:Android中的GreenDao框架修改数据库的存储路径


下一篇:Android利用反射机制为实体类属性赋值