Skip to main content
2 of 2
replaced http://stackoverflow.com/ with https://stackoverflow.com/
user avatar
user avatar

Compile-time string expressions are put into the String pool. s=s+"JVM" is not a compile-time constant expression. so everytime it creates a new string object in heap.

for more details see this Behavior of String literals is confusing

Darshan
  • 457
  • 3
  • 18