Java string literal pool

Jun Zhuang jun.zhuang at hobsons.com
Mon Aug 29 13:29:08 UTC 2016


Hi,

I was reading about the Java8 Metaspace the other day, then got into the topic of string pool. I got conflicting information regarding a couple of things, I wonder if I can get a definitive answer from the experts?

#1: Is the string literal/constant pool a heap area that holds actual string literal objects or a place that holds references to string literal objects?
Reference: http://stackoverflow.com/questions/11700320/is-string-literal-pool-a-collection-of-references-to-the-string-object-or-a-col

#2: Is the following statement correct?

String str = new String("Cat");
In above statement, either 1 or 2 string will be created. If there is already a string literal "Cat" in the pool, then only one string "str" will be created in the pool. If there is no string literal "Cat" in the pool, then it will be first created in the pool and then in the heap space, so total 2 string objects will be created.

>From http://www.journaldev.com/797/what-is-java-string-pool#comment-36152


Apprciate your answers,
Jun

Jun Zhuang
Sr. Performance QA Engineer | Hobsons<https://www.hobsons.com/?utm_source=outlook&utm_medium=email&utm_campaign=banner_02.12.16_general>
T: +1 513 746 2288 | jun.zhuang at hobsons.com
50 E-Business Way, Suite 300 | Cincinnati, OH 45241 | USA


Upgraded by Hobsons - Subscribe Today
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/hotspot-gc-use/attachments/20160829/8f2ef05b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image550000.png
Type: image/png
Size: 13602 bytes
Desc: image550000.png
URL: <http://mail.openjdk.java.net/pipermail/hotspot-gc-use/attachments/20160829/8f2ef05b/image550000.png>


More information about the hotspot-gc-use mailing list