1
String abc= new String ("Hello");//will create new instance  

and

 String abc="Hello";//will not create new instance  

When the string is created as literal the value "Hello" will be in the string constant pool and the reference will be in stack , What about the String object.where does its memory allocation happen?

What does the intern() method do?

Which is more efficient?

trincot
  • 317,000
  • 35
  • 244
  • 286
Nithin Varghese
  • 258
  • 3
  • 12
  • Stack memory is used to store local variables and function call, while heap memory is used to store objects in Java. So String objects are also placed in heap. – Bhavik vora Mar 26 '15 at 04:13

0 Answers0