Technical Discussion :: Java
Home > Technical Interview Q&A > Java > Discussion
18 / 66
What is the difference between creating String as new() and literal?
Answer:
When 'new String()' is used, it creates a new string object in the heap memory and as when literal is used, it may return an existing object from the string pool, it exists else creates a new object.
Asked In ::
Rakool
13 Oct, 2019 1:07 PM
When 'new String()' is used, it creates a new string object in the heap memory and as when literal is used, it may return an existing object from the string pool, it exists else creates a new object.