String字符串,求大神帮解答下

String s9 = "hello"+"world";
String s10 = "helloworld";
System.out.println(s9==s10);
String s11 = s4+"world";

    System.out.println(s10==s11);

    s10与s11不同的原理是什么??

s4在哪里定义的。如果s4不是在程序编译的时候确定的,那么它不在常量池中,不是一个对象引用,所以==返回false。要比较字符串字面值,应该用equals

你问的完整代码应该是这样的吗?

String s9 = "hello"+"world";
String s10 = "helloworld";
System.out.println(s9==s10);
String s11 = s4+"world";
System.out.println(s11==s10);

==:是用来判断两个对象的地址是否相同,即是否是指相同一个对象。

==是双目运算符,结果是一个bool值