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.
Asked
Active
Viewed 115 times
0
-
Show your effort before you ask for help. – Harsh Wardhan Jun 10 '17 at 07:11
1 Answers
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