javastringg1gc

In what way String Deduplication is different from String interning


As we know In Java String, process of storing and maintaining only one literal of any String is String interning. I felt String Deduplication serves the same purpose when I read it first time.

could some one explain Deduplication advantage over String intern?


Solution

  • String interning happens only for constant strings and strings that you manually intern.

    String deduplication happens automatically in the background for all strings, including ones you create at runtime.