public class Opinion {
public static void main(String[] args) {
String tom=new String("I am student");
String mary=new String("I am student");
String kim="I love you";
String sim="I love you";
boolean b=(tom==mary);
boolean b1=(kim==sim);
System.out.println(b);
System.out.println(b1);
}
}
这个输出的结果是:false
true
这是为什么啊?String tom="I am student";和String tom=new String("I am student");这两种字符串表达方式不是一样的么,可为什么输出的结果不同?