0
I am trying to present it from a Java context which should match the problem though.
To talk in simple form.
'new()' and 'literal' live in different memory of a machine.
Lets say literal lives in m1 and new() lives in m2.
When you do:
String s1 = "Hello";
The CPU looks for the "Hello" in m1 and if CPU doesn't find it then it creates it. But if CPU does find that there already is "Hello" then it simply gives the s1 the address of that "Hello" in m1.
When you do:
String s2 = new String("Hello");
The CPU creates "Hello" in m2. CPU doesn't care if there already is the same "Hello" in m2.
So, if you do:
boolean areTheyEqual = s1==s2;
the answer is false;
But if you do:
areTheyEqual = s1.equals(s2);
the answer is true;