In computer science, string interning is a method of storing only one copy of each distinct string value, which must be immutable. Interning strings makes some string processing tasks more time- or space-efficient at the cost of requiring more time when the string is created or interned. The distinct values are stored in a string intern pool.
The single copy of each string is called its 'intern' and is typically looked up by a method of the string class, for example
String.intern in Java. All compile-time constant strings in Java are automatically interned using this method.
Objects other than strings can be interned. For example, in Java, when primitive values are boxed into a wrapper object, certain values (any
char from 0 to 127, and any
int between -128 and 127) are interned, and any two boxing conversions of one of these values are guaranteed to result in the same object.
... String interning speeds up string comparisons, which are sometimes a performance bottleneck in applications (such as compilers and dynamic programming ... Without interning, checking that two different strings are equal involves examining every character of both strings ... With interned strings, a simple object identity test suffices after the original intern operation this is typically implemented as a pointer equality test, normally just a single ...
Famous quotes containing the word string:
“As I came home through the woods with my string of fish, trailing my pole, it being now quite dark, I caught a glimpse of a woodchuck stealing across my path, and felt a strange thrill of savage delight, and was strongly tempted to seize and devour him raw; not that I was hungry then, except for that wildness which he represented.”
—Henry David Thoreau (18171862)