The following code (from an interview) produces an output of false
, but I believe it should be true
.
public static void main(String[] args) {
String a = "hello";
String b = a + "world";
String c = "helloworld";
System.out.println(b==c);
}
I thought that constant String expressions were interned, and a + "world"
is a constant, so it should intern "hello world"
.
Can someone explain why the output is false
?