Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 1
    "stackoverflow" will be in the pool, s won't. Commented Feb 7, 2014 at 7:43
  • Yes, so we end up with two copies of "stackoverflow" - the literal one in the constant pool, plus s on the heap. Commented Feb 7, 2014 at 7:47
  • Omoro is correct. In this case the new String is being created from a String constant though. So the constant is added to the string pool, from that constant a new String object is created in the heap. Commented Feb 7, 2014 at 7:47
  • 1
    @TimB, Your (perfectly correct) comment seems to contradict your answer. Commented Feb 7, 2014 at 7:48
  • @Omoro the literal "stack overflow" is first created and goes to the pool then a new String is creating using the copy constructor which will not be in the pool. Commented Feb 7, 2014 at 7:49