DEV Community

Ratik Mahajan
Ratik Mahajan

Posted on

Strings in java language

Java strings

  • Java Strings are array of characters.
  • Java Strings are immutable : which means once Strings are created in the String pool they can't be changed.
  • Strings were earlier stored in Permgen and from java 7 onwards strings in java are stored in the heap. this makes string available for the garbage collection if it is not referenced anywhere in the memory.
  • Strings in java are created through new keyword and java String literals. Strings created through new keyword are stored in heap and Strings created through literals are stored in the string pool(heap) from java 7 onwards. String pool would mean intern of the string.

Why do we intern Strings in java

  • This reduces the memory footprint of string in java.

Top comments (0)