When should we use intern method of String on String literals

后端 未结 14 816
生来不讨喜
生来不讨喜 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条回答
  •  旧时难觅i
    2020-11-22 08:42

    String literals and constants are interned by default. That is, "foo" == "foo" (declared by the String literals), but new String("foo") != new String("foo").

提交回复
热议问题