When we create a String using = we create (if it does not exist) a new String literal in the String pool. I know the String pool contains only unique values.
Step 1:
String var1 = "Java";
OK. We now have 1 literal in the String pool and 1 object created in the Heap. Now if we create String using new String() with the same literal value:
Step 2:
String var2 = new String("Java");
We now have 2 different objects created in the heap. The main question is: Do both String literals refer to the one in the String pool or do we have one String literal var1 - "Java" and one that's outside that String pool var2 - "Java"?
I just want to know do we have one literal or two literals or 1 in the String pool and one outside (waiting to be added to the String pool).