In the first case, you can take this string from the pool, if it exists. In the second case, you explicitly create a new string object.
You can check this on these lines:
String s1 = "blahblah"; String s2 = "blahblah"; String s3 = new String("blahblah"); String s4 = s3.intern(); System.out.println(s1 == s2); System.out.println(s1 == s3); System.out.println(s2 == s3); System.out.println(s1 == s4); Output: true false false true
source share