Had a simple question around Stringz instance pooling in Java
If I have a situation like this: Scenario 1:
String s1 = "aaa";
String s2 = new String("aaa");
and then flipped Scenario 2:
String s1 = new String("aaa");
String s2 = "aaa";
In each case- how many objects are being created in the String Pool and Heap ? I assumed both would create an equal number of objects (2 Objects - one single "aaa" for both lines in each scenario in the String pool and one for the new Operator). I was told in an iview that this wasn't correct - I'm curious as to what is wrong with my understanding?