static String intern(String str) {
synchronized (internTable)
{
WeakReference ref = (WeakReference) internTable.get(str);
if (ref != null)
{
String s = (String) ref.get();
// If s is null, then no strong references exist to the String;
// the weak hash map will soon delete the key.
if (s != null)
return s;
}
internTable.put(str, new WeakReference(str));
}
return str;
}
Fetches this String from the intern hashtable. If two Strings are
considered equal, by the equals() method, then intern() will return the
same String instance. ie. if (s1.equals(s2)) then
(s1.intern() == s2.intern()). All string literals and string-valued
constant expressions are already interned. |