org.apache.hadoop.util

## Class StringInterner

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

-     @InterfaceAudience.Public
       @InterfaceStability.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 and Description
    `StringInterner()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and 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 Detail

    - #### StringInterner

          public StringInterner()

  - ### Method Detail

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

Copyright © 2008–2022 Apache Software Foundation. All rights reserved.