*
The moose likes Beginning Java and the fly likes H&P Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "H&P" Watch "H&P" New topic
Author

H&P

muhd yousuf
Greenhorn

Joined: Oct 09, 2001
Posts: 3
what is the difference between heep & pool in Strings?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
If you use the special syntaxes for String the JVM will try to optimize by re-using Strings that already exist in the Pool. This is more efficient if there are duplicate strings. The special syntaxes include
String s = "asfasfasd"; //directly naming
String x = s + "sdfsd"; // concatenation
If you make a String using the "new" operator an object will be created on the heap (where most objects live) even if there is a string object in the pool which matches it.
See this thread from yesterday. http://www.javaranch.com/ubb/Forum33/HTML/003680.html

[This message has been edited by Cindy Glass (edited October 09, 2001).]


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: H&P