StringInterner (Apache Hadoop Common 3.5.0 API)
Description: declaration: package: org.apache.hadoop.util, class: StringInterner

Package org.apache.hadoop.util

# 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 Summary

  Constructors
  Constructor
  Description
  `StringInterner()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static String[]`
  `internStringsInArray(String[] strings)`
  Interns all the strings in the given array in place, returning the same array.
  `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.
  `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.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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.