0

I want to create an object of string on the heap and I have to make sure that the object is not created on string pool.

trincot
  • 317,000
  • 35
  • 244
  • 286

1 Answers1

0

Java by default doesn't put String objects into the string pool, instead, they give you the flexibility to explicitly store any arbitrary object in the string pool by calling intern().

Use the new operator to force String class to create a new String object in heap space.

Also note, in Java 7 – the string pool was relocated to the main heap area from the permgen area of the heap.

Devarsh Desai
  • 5,984
  • 3
  • 19
  • 21