String Pool

public class StringEquals {
 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.
String Pool Caches and you create a String object as a literal without the "new" keyword for caching

Comments

Popular posts from this blog

தட்டு வண்டியில் காளிக்கோயில் - சிறுகதை

பிரேமாவின் பெண் குழந்தை

தீபம் பிளக்ஸ்