Java String "constant" confusion
I'm slightly confused and obviously missing something here:
I read that java.lang.String's "are constant; their values cannot be
changed after they are created."
But if i write the following code:
String line;
line = "Test1";
System.out.println(line);
line = "Test2";
System.out.println(line);
The terminal outputs:
Test1
Test2
It appears I am able to set a value, and then set another value for the
string later.
No difference if i try this way:
String line2 = "Test3";
System.out.println(line2);
line2 = "Test4";
System.out.println(line2);
I am still able to set the value after its been set initially.
Where have I gone wrong here?
Thanks.
No comments:
Post a Comment