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*

5
  • So what I have understood from this is that when we use "+" operator with a string variable (NOT a literal) then new object is created? Commented Nov 19, 2015 at 10:45
  • @swdeveloper It is slightly more complicated than that, I added a link to the definition of "constant expression", Commented Nov 19, 2015 at 10:47
  • "As an interesting aside, if in the code above you add the final modifier to s3, that makes s3 + " Computer" a constant expression again, and both comparisons will print true" Great point! Commented Nov 19, 2015 at 11:10
  • One more thing to clear about "pool of string objects" (because I have seen this phrase in may SO answers and other websites); Is it a fixed memory assigned to string objects? If yes, then how much size is assigned to it and what if there are so many string objects and the size of total string objects is larger than the assigned memory? Commented Nov 19, 2015 at 11:11
  • @swdeveloper That should really be a separate question: the sizing and behaviour of the string pool differs between Java versions. But you can find a good overview here. Commented Nov 19, 2015 at 11:48