new String() vs literal string performance

前端 未结 4 2089
名媛妹妹
名媛妹妹 2020-12-05 15:07

This question has been asked many times on StackOverflow but none of them were based on performance.

In Effective Java book it\'s given tha

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-05 15:14

    The JVM maintains a pool of references to unique String objects that are literals. In your new String example you are wrapping the literals with an instance of each.

    See http://www.precisejava.com/javaperf/j2se/StringAndStringBuffer.htm

提交回复
热议问题