Real Life, Practical Example of Using String.intern() in Java?

后端 未结 5 1120
挽巷
挽巷 2021-01-01 11:47

I\'ve seen many primitive examples describing how String intern()\'ing works, but I have yet to see a real-life use-case that would benefit from it.

The only situati

5条回答
  •  独厮守ぢ
    2021-01-01 12:06

    Not a complete answer but additional food for thought (found here):

    Therefore, the primary benefit in this case is that using the == operator for internalized strings is a lot faster than use the equals() method [for not internalized Strings]. So, use the intern() method if you're going to be comparing strings more than a time or three.

提交回复
热议问题