Javatpoint Logo
Javatpoint Logo

Java String intern()

The java string intern() method returns the interned string. It returns the canonical representation of string.

It can be used to return string from memory, if it is created by new keyword. It creates exact copy of heap string object in string constant pool.


Signature

The signature of intern method is given below:


Returns

interned string


Java String intern() method example

Test it Now
false
true

Java String intern() Method Example 2

Let's see one more example to understand the string intern concept.

Test it Now
true
false
true
false
true
false




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA