Class SymbolTable


  • public final class SymbolTable
    extends java.lang.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 Summary

      Constructors 
      Constructor Description
      SymbolTable()
      Constructs a new, empty SymbolTable.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String internSymbol​(java.lang.String symbol)
      Return an interned version of a symbol.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SymbolTable

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

      • internSymbol

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