class EqualDemo
{
public static void main(String args[])
{
String s1="Hello";
String s2="hello";
String s3="Good - bye";
String s4="HELLO";
System.out.println(s1 + "equals" + s2 +"->" + s1.equals(s2));
//用s1的字符串和s2字符串做比较结果不相等,因为区分大小写;
System.out.println(s1 + "equals" + s3 +"->" + s1.equals(s3));
//用s1的字符串和s3字符串做比较结果不相等,因为根本不相等;
System.out.println(s1 + "equals" + s4 +"->" + s1.equals(s4));
//用s1的字符串和s4字符串做比较结果不相等,因为区分大小写;
System.out.println(s1 + "equalsIgnoreCase" + s4 +"->" + s1.equalsIgnoreCase(s4));
//用s1的字符串和s4字符串做比较结果不相等,不区分大小写;返回值是对的
}
} |
|