CSC300 / CSC402: String Interning [9/24] Previous pageContentsNext page

String a = new String ("Hello");
String b = new String ("Hello");
String x = a.intern();
String y = b.intern();
x=Hello, y=Hello
                  x==y : true
   Objects.equals(x,y) : true
           x.equals(y) : true
eqs04

String's intern method looks for a canonical representation of the string.

Previous pageContentsNext page