I have created strings object as given below
Case 1:
String s1="mystring";//Address location is 1000
String s1="yourstring";
String s2="mystring";
Case 2:
String s1=new String("mystring");//Address location is 1000
String s1=new String("yourstring");
String s2=new String("mystring");
with ref.
As per my knowledge these string are stored in string constant pool for Case1 with specific memory locations, similarly in case2 objects are created in Heap memory. How does these memory will be managed and freed by garbage collector if we assign same or different strings to String objects.