class StringTest{
public static void main(String args[]){
String str="This is the first string.";
boolean result1=str.equals(''This is the first string.");
boolean result2=str.equals("this is the first string.");
boolean result3=str.equalsIgnoreCase("this is the first string.");
System.out.println("result1="+result1);
System.out.println("result2="+result2);
System.out.println("result3="+result3);
}
}
本文通过一个简单的Java程序演示了如何使用equals和equalsIgnoreCase方法来比较字符串。程序定义了一个名为StringTest的类,并在main方法中创建了一个字符串实例,然后分别用equals和equalsIgnoreCase方法与其他字符串进行比较,最后输出比较结果。
1万+

被折叠的 条评论
为什么被折叠?



