Underlying mechanism of String pooling in Java?

后端 未结 7 1710
不知归路
不知归路 2020-12-15 18:09

I was curious as to why Strings can be created without a call to new String(), as the API mentions it is an Object of class java

相关标签:
7条回答
  • 2020-12-15 18:36

    String pool as it is pool of string stored in heap for exp:

    String s="Test";
    String s1="Test";    
    

    both gets stored in heap and refers to a single "Test" thus s1=s, while

    String s=new String("Test");
    

    is an object that also get stored in heap but different form s1=s refer here

    0 讨论(0)
提交回复
热议问题