Are the below two pieces of code the same?
String foo = \"foo\"; String foo = new String(\"foo\").intern();
Yes, they are same. Basically intern() returns a representation of a string that is unique across the VM. This means you can use == instead of .equals() to compare the strings, saving on performance.
intern()
==
.equals()