• Register

Share:- Whatsapp Facebook Facebook

------------------------------------- Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.


0 votes

Why use string intern method in java.lang.string. Can you give an idea about String intern() method.

in Java by

1 Answer

0 votes

As you know about the java string memory pool:

This  (String intern pool) is a special storage area in Java heap. When a string is created in the pool and if the string already exists, then the reference of the existing string will be returned, otherwise creating a new object and return its reference.

For more: http://www.developerhelpway.com/forum/321/why-string-class-is-final-or-immutable-in-java?show=322#a322

The java string intern() method use for following purposes:

The same String is available in memory pool then:

  1. If it exists, returns it.
  2. Else, adds this String to the memory pool and returns the String.