intern() method
This method will provide you with the canonical representation of the string. The string will be returned from memory if it is created using the new keyword. It will also create a copy of the object of the string from the heap in the constant pool.
Syntax-
Example-
Output-