Java string immutability
The theory of the immutability of the String class says that once created, a string can never be changed. Real life experience with Java programming implies that this is not true. Take the following code EX1: public class ImString{ public static void main(String argv[]){ String s1 = new String("Hello"); String s2 = new String("There"); System.out.println(s1); s1=s2; System.out.println(s1); } } If Strings cannot be changed then s1 should still print out Hello, but if you try this snippet you will find that the second output is the string "There". What gives? The immutability really refers to what the String reference points to. When s2 is assigned to s1 in the example, the String containing "Hello" in the String pool is no longer referenced and s1 now points to the same string as s2 . The fact that the "Hello" string has not actually been modified ...