public static void main(String[ ] args) {
String s1 = "Hello";
String s2 = new String(s1);
String s3 = "Hello";
System.out.println(s1 + " equals " + s2 + "--> " + s1.equals(s2)); //true
System.out.println(s1 + " == " + s2 + " --> " + (s1 == s2)); //false
System.out.println(s1 + " == " + s3+ " --> " + (s1 == s3)); //true
}
}
In Java 6 — all interned strings were stored in the PermGen – the fixed size part of heap mainly used for storing loaded classes and string pool.
In Java 7 – the string pool was relocated to the heap. So, you are not restricted by the limited size.
No comments:
Post a Comment