The == compare the reference - the address of the string not the value of it. For comparing strings you should use equals. The JVM will handle new String objects, so if an object of the same value exists (string2 vs string3) it might reference the same one.