Consider the code :
public class Stringer {
public static void main(String[] args) {
String s1 = "SomeLine";
System.out.println(s1); // prints SomeLine
s1 = "AnotherLine";
System.out.println(s1); // prints AnotherLine
}
}
When I change s1
from SomeLine
to AnotherLine
, since Strings are Immutable , does this mean that SomeLine
is lost and is eligible for GC ?
Much appreciated