What is the difference between creating String as new() and literal ?5
1039 5b5cc6dee4d2b4197774ea50
Q: What is the difference between creating String as new() and literal ?
- Show Answer
- Workspace
- Discuss
Answer :
Explanation :
When we create string with new() Operator, it’s created in heap and not added into string pool while String created using literal are created in String pool itself which exists in PermGen area of heap. String s = new String("Test"); does not put the object in String pool , we need to call String.intern() method which is used to put them into String pool explicitly. its only when you create String object as String literal e.g. String s = "Test" Java automatically put that into String pool.
Similar Questions
Since Nithya and Suganya exchange places, so Rita’s new position is the same as Monika’s earlier position. This position is 17th from the right and 10th from the left. Therefore Number of girls in the row = (16 + 1 + 9) = 26.