Class SymbolTable


  • public final class SymbolTable
    extends Object
    This class is used to optimize the use of String.intern() when it is used on a sequence of strings that are frequently repeated.

    The call to String.intern() is a relatively expensive operation because of synchronization and the creation of weak references. This class caches strings that it has already interned to avoid calling repeating the call to intern.

    The implementation uses a String[] to implement the hash table. The reason for using this implementation instead of a collection class is to avoid the overhead of creation of many entry objects, as most hash set implementations would do. This implementation also doesn't attempt to resize the table if it becomes full. In that case, it simply stops caching new entries, and falls back to simply interning any uncached strings.

    • Constructor Detail

      • SymbolTable

        public SymbolTable()
        Constructs a new, empty SymbolTable.
    • Method Detail

      • internSymbol

        public String internSymbol​(String symbol)
        Return an interned version of a symbol.
        Parameters:
        symbol - a string to be interned.
        Returns:
        the interned string.