Strings in java language

ranujmahajan

Ratik Mahajan

Posted on February 21, 2024

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.
💖 💪 🙅 🚩
ranujmahajan
Ratik Mahajan

Posted on February 21, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Strings in java language
java Strings in java language

February 21, 2024

Strings in java language
java Strings in java language

February 21, 2024