package MyString;
/*
Object:是类层次结构中的根类,所有的类都直接或者间接继承自该类
如果一个参数的形式参数是Object,那么我们就可以传递它的任意子类对象
String类的判断功能:
boolean equals(Object obj):比较字符串的功能是否相同
boolean equalsIgnoreCase(String str):比较字符串的内容是否相同(不考虑大小写)
boolean startsWith(String str):判断字符串是否以指定的字符str开头
boolean endsWith(String str):判断字符串是否以指定的字符str结尾
*/
public class Object {
public static void main(String[] args) {
String s1="hello";
String s2="hello";
String s3="Hello";
//boolean equals(Object obj):比较字符串的功能是否相同
System.out.println("-----------------------------------");
System.out.println(s1.equals(s2));
System.out.println(s1.equals(s3));
System.out.println("-----------------------------------");
//boolean equalsIgnoreCase(String str):比较字符串的内容是否相同(不考虑大小写)
System.out.println(s1.equalsIgnoreCase(s3));
System.out.println(s1.equalsIgnoreCase(s2));
System.out.println("-----------------------------------");
//boolean startsWith(String str):判断字符串是否以指定的字符str开头
System.out.println(s1.startsWith("he"));
System.out.println(s3.startsWith("He"));
System.out.println("-----------------------------------");
//boolean endsWith(String str):判断字符串是否以指定的字符str结尾
System.out.println(s3.endsWith("llo"));
System.out.println("-----------------------------------");
}
}
String类的判断功能
最新推荐文章于 2022-01-05 21:33:13 发布