I ran the following program,
String firstString = "String"; String secondString = "String"; String thirdString = new String("String"); System.out.println(firstString == secondString); System.out.println(firstString == thirdString); System.out.println(firstString.intern() == thirdString); System.out.println(firstString.intern() == thirdString.intern()); System.out.println(firstString.intern().equals(thirdString.intern())); System.out.println(firstString == thirdString);
and my result was
true false false true true false
I found out that the jvm pool is the pool with the same contents as the strings. It is right? If thats true, then why not firstString == thirdString returns false? Is jvm a pool of string initialization only: "", and not with a new operator?
vvekselva
source share