Ex xamples String s ="Welcome to Java String String s1 new String("Welcome to Java")i Interned string object for Welcome to java String s2 s. intern String s3 =Welcome to Javai String System. out. printin ("s1 ==s is +(s1== s) A string object for System. out. printIn("s2==s is +(s2== s) WElcome to Java ystem out println( s3 is +( s3)); display a new object is created if you use the new operator s Is false 02==s is true If you use the string initializer, no new object is created if the interned object is 6 3 is true already created iang, Introduction to Java Programming, Sixth Edition, (c)2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6 10 Examples display s1 == s is false s2 == s is true s == s3 is true A new object is created if you use the new operator. If you use the string initializer, no new object is created if the interned object is already created. String s = "Welcome to Java"; String s1 = new String("Welcome to Java"); String s2 = s.intern(); String s3 = "Welcome to Java"; System.out.println("s1 == s is " + (s1 == s)); System.out.println("s2 == s is " + (s2 == s)); System.out.println("s == s3 is " + (s == s3)); : String Interned string object for "Welcome to Java" : String A string object for "Welcome to Java" s s1 s2 s3