1.String s1 = new String("hello"); 2.String s2 = new String("hello"); 3.System.out.println(s1==s2):

来源:学生作业帮助网 编辑:作业帮 时间:2024/06/17 20:56:50

1.String s1 = new String("hello"); 2.String s2 = new String("hello"); 3.System.out.println(s1==s2):

呃,什么问题呢?这几句话输出的结果是:false.s1,s2指向的对象内容相同,但是本身是不同的.如果使用s1.equals(s2),则是true.