I read
String s = new String("Hello")
will create two object one in heap and other one in String Pool.
But how can we check and confirm that exactly 2 Objects get created.(I am using Eclipse)
I read
String s = new String("Hello")
will create two object one in heap and other one in String Pool.
But how can we check and confirm that exactly 2 Objects get created.(I am using Eclipse)
Actually it won't always create two objects as the String "Hello" may already be in the String pool.
Either way, in order to check you should use something like jmap -heap
(which comes with the jdk) before and after. It will show you heap summaries.
I assume this is an academoc exercise btw. As LionC comments, you shouldn't ever construct Strings in this way.