class StringTest
{
static boolean f1()
{
String str1 = new String("blue_仰望");
String str2 = new String("blue_仰望");
//String str3 = str1;
return str1==str2;
}
static boolean f2()
{
String str1 = new String("blue_仰望");
//String str2 = new String("blue_仰望");
String str3 = str1;
return str1==str3;
}
static boolean f3()
{
String str1 = "blue_仰望";
String str2 = "blue";
String str3 = str2 + "_仰望";
return str1==str3;
}
static boolean f4()
{
String str1 = new String("blue_仰望");
String str2 = new String("blue_仰望");
return 0==str1.compareTo(str2);
}
static boolean f5()
{
String str1 = new String("blue_仰望");
String str2 = new String("blue_仰望");
return str1.equals(str2);
}
public static void main(String[] args)
{
if(f1()) //false
System.out.println("f1()为真");
else
System.out.println("f1()为假");
if(f2()) //true
System.out.println("f2()为真");
else
System.out.println("f2()为假");
if(f3()) //false
System.out.println("f3()为真");
else
System.out.println("f3()为假");
if(f4()) //true
System.out.println("f4()为真");
else
System.out.println("f4()为假");
if(f5()) //true
System.out.println("f5()为真");
else
System.out.println("f5()为假");
}
}
Java字符串的等于不等
最新推荐文章于 2021-04-21 18:39:30 发布