• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

H&P

 
muhd yousuf
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference between heep & pool in Strings?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic