//求解,那个false是为什么,难道不是比较的值吗?
public class Tese {
public static void main(String[] args) {
boolean a=function_1();
boolean b=function_2();
boolean c=function_3();
boolean d=function_4();
//结果都是true
System.out.println(a);
System.out.println(b);
//反转后结果应该是一样的,然后用==和equals得出两种结果,一个false 一个true
System.out.println(c);
System.out.println(d);
}
public static boolean function_1(){
String a="a";
String b="a";
return a==b;
}
public static boolean function_2(){
String a="a";
String b="a";
return a.equals(b);
}
public static boolean function_3(){
String s="123321";
StringBuilder sb=new StringBuilder(s);
String str=sb.reverse().toString();
return s==str;
}
public static boolean function_4(){
String s="123321";
StringBuilder sb=new StringBuilder(s);
String str=sb.reverse().toString();
return s.equals(str);
}
}
天将明96
相关分类