The Java Zone is brought to you in partnership with JetBrains. Learn more about Kotlin, a new programming language designed by JetBrains to solve problems that software developers face every day.
A String based puzzle for you.
The following program
String te = "te", st = "st";
String username = te + st;
System.out.println("String object the same is: "
+ (username == "test"));
prints under Java 7 update 7.
String object the same is: true
but uncomment the "test".length(); line, or run with Java 6 and it prints
String object the same is: false
Can you work out why?
The Java Zone is brought to you in partnership with JetBrains. Discover how powerful static code analysis and ergonomic design make development not only productive but also an enjoyable experience.
Published at DZone with permission of
, DZone MVB
Opinions expressed by DZone contributors are their own.