62,623
社区成员
发帖
与我相关
我的任务
分享
public class test {
public static void main(String args[]){
String a = "abc";
String b = "abc";
if (a==b){ //比较的是引用地址!因为a和b指向同一个对象,所以相等
System.out.println("a==b");
}
if (a.equals(b)){ //String类重写了从Object继承过来的equals方法,重写为比较他们的内容!
System.out.println("a equals b");
}
}
}