It's not a secret anymore!
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


muhd yousuf

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

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.

[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:
subject: H&P
jQuery in Action, 3rd edition