aspose file tools*
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
Author

use of Intern() method of String

Noorulain Khan
Greenhorn

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

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


JavaBeginnersFaq
"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"
Sheriff

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: use of Intern() method of String