Re:JVM Anatomy Quark #10: String.intern (2019)
by jamesfinlayson on Wednesday June 22, 2022 @08:53PM
(#31843852)
That would explain it - I think I first touched Java in 2009 or 2010 and this is the first I've heard of String.intern in all that time.
String.intern() also offers some other benefits for certain use cases. Earlier versions of java did not cache the String hashcode, which meant that to use Strings as hash table keys meant hashing a lot more. But, an interned string can be used in an IdentityHashMap, which was faster for a long portion of Java's early life.
(I worked on a moderately popular Java library that targeted Java 1.5 as the minimum version. It does occasionally come up useful, but only in specific, and increasingly rare circumstances)