Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




Java - Strings in Heap


How are String values managed in the Heap?


When we create a String data type using the new operator,


String firstString = new String("Robert");

A memory space will be created for firstString in so called heap and the value Robert will be stored in it.


Now, if we define another String type variable secondString and assign the same value Robert to it,


String secondString = new String("Robert");

Java creates a new memory space for secondString and the value Robert will be assigned to it.

Spring_Boot