12.6 Difference b/w literal and new
Difference between creating String object by literal and new operator.
- We have already seen the creating of String objects in three ways.
- Now its time to get to know mainly the difference between creating String object by using literal and new.
- Only String class having two types of memory locations to store String objects which are Heap and String Constant Pool memory.(SCP)
- Here SCP is available inside Heap memory.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5Bagx0F5BoNs6XmGrakXrtjtOyCTs_FQLi3GiSZFdtPanXu1PIP_QF56oLtuEnmpnSPggp_8W4QJ-xmsQf6PGNvlNGeUxPh3UlEGwTrdAu-ADPIdovHT4sdiRb3o_Mt29G1wtzXZvZAF5/s320/String+memory.png)
- Based on the type of String object creation, these objects will be stored either in heap or String Constant Pool memory.
Nireekshan