When should we use intern method of String on String literals

后端 未结 14 779
生来不讨喜
生来不讨喜 2020-11-22 08:11

According to String#intern(), intern method is supposed to return the String from the String pool if the String is found in String pool, otherwise a new string

14条回答
  •  隐瞒了意图╮
    2020-11-22 08:43

    http://en.wikipedia.org/wiki/String_interning

    string interning is a method of storing only one copy of each distinct string value, which must be immutable. Interning strings makes some string processing tasks more time- or space-efficient at the cost of requiring more time when the string is created or interned. The distinct values are stored in a string intern pool.

提交回复
热议问题