Class StringInterner

java.lang.Object
org.apache.hadoop.util.StringInterner

@Public @Stable public class StringInterner extends Object
Provides string interning utility methods. For weak interning, we use the standard String.intern() call, that performs very well (no problems with PermGen overflowing, etc.) starting from JDK 7.
  • Constructor Details

    • StringInterner

      public StringInterner()
  • Method Details

    • strongIntern

      public static String strongIntern(String sample)
      Interns and returns a reference to the representative instance for any of a collection of string instances that are equal to each other. Retains strong reference to the instance, thus preventing it from being garbage-collected.
      Parameters:
      sample - string instance to be interned
      Returns:
      strong reference to interned string instance
    • weakIntern

      public static String weakIntern(String sample)
      Interns and returns a reference to the representative instance for any of a collection of string instances that are equal to each other. Retains weak reference to the instance, and so does not prevent it from being garbage-collected.
      Parameters:
      sample - string instance to be interned
      Returns:
      weak reference to interned string instance
    • internStringsInArray

      public static String[] internStringsInArray(String[] strings)
      Interns all the strings in the given array in place, returning the same array.
      Parameters:
      strings - strings.
      Returns:
      internStringsInArray.