I know that
String s1 = "test";
String s2 = new String("test");
System.out.println(s1==s2); // false
in above snippet "test" String Object is created inside the String pool in java (s1 will be passed its reference) and a new String Object will be created in the heap space of the memory (s2 will be in heap sapce).
so will s2 String object be referring to the String pool's "test" String object internally or s2 keeps an altogether different "test" String Object in memory ?
what will be the effect if we somehow "test" String Object in String constant pool is removed ? will s2 still be having the value "test" ?
I know this topic has been touched a lot but none of the previous answers which i checked clarifies it.
please mention any sources if that has a better explanation.
Thanks in advance !