sample application to demonstrate inturn method
package stringclass;
public class StringInternMethod {
public static void main(String[] args) {
String s1=new String("viswan");
String s2=s1;
//Intern() method used to point the String constant pool object instead of heap object
String s3=s1.intern();
System.out.println(s1==s3); //false
String s4="viswan";
System.out.println(s4==s3); //true
}
}
output:
false
true
0 comments:
Post a Comment