Two Laptop Bag
The moose likes Beginning Java and the fly likes use of Intern() method of String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "use of Intern() method of String" Watch "use of Intern() method of String" New topic

use of Intern() method of String

Noorulain Khan

Joined: Jul 31, 2001
Posts: 28
What is the use of intern method with string while considering on heap and pool
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9056
intern() causes the String to go into the String pool.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
This would be important if the String had been created using the new operator and therefore was out on the heap - not a good place to be if you want to optimize by re-using the same object in multiple places.
For efficiency you might force that object into the pool using intern(). Now it is available to be referenced for any other STrings that have the same value.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Have you checked out Aspose?
subject: use of Intern() method of String
It's not a secret anymore!