Originally posted by S Thiyanesh:
String str1 = "Hello";
String str2 = "Hello";
This creates only one String object.
[ June 20, 2006: Message edited by: S Thiyanesh ]
Congtatz !! U nailed this one. Remember in JVM pool, Strings are optimized agressively. Thats wat I remember from my
SCJP when I read the JVM specs.
So above code **WILL** create just one monitor. Even though they may be many references to it. Dont care about them
Beware of writing like this. This will break.
String str2 = new String("hello");
Cheers