public static void Main (string[] args) {
String S1 = new StringBuilder ("Computer"). Append ("Software"). toString ();//In the heap
System.out.println (S1.intern () ==s1);//Intern Returns a value pointing to the heap "reference to computer software" with S1 pointing to the same piece of heap memory, same, returns True
String d= "class";//Add "class" string constant to the constant pool in the method area
String s2 = new StringBuilder ("CLA"). Append ("ss"). ToString ();//stringbuilder is created in the heap
System.out.println (S2.intern () ==s2);//If already in the constant pool, intern () after jdk1.7 returns a reference to a string in the heap, so it differs from the string constant class in the method area. Returns false
If both jdk1.6 and before, two return false. Because the previous intern () directly returns a reference to the corresponding string in the constant pool in the method area. The reference to the object in the heap must be different from the StringBuilder
}
Java jdk1.7 after Sting intern () method differs from the previous