String intern puzzles
- by Yob
On this blog I found interesting String puzzles:
--- Quote ---
String te = "te", st = "st";
//"test".length();
String username = te + st;
username.intern();
System.out.println("String object the same is: "
+ (username == "test"));
prints
String object the same is: true
but uncomment the "test".length(); line and it prints
String object the same is: false
--- EoQ ---
Being honest I don't understand why the outputs are different. Could you please explain me what's the cause of such behaviour?