Code For NonGeek
Would you like to react to this message? Create an account in a few clicks or log in to continue.

What is the difference between creating String as new () and literal?

Go down

What is the difference between creating String as new () and literal? Empty What is the difference between creating String as new () and literal?

Post  Admin Sat Oct 15, 2011 5:26 pm

When we create string with new () 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 Perm area of heap.


String s = new String("Test");
will put the object in String pool , it it does then why do one need String.intern() method which is used to put Strings into String pool explicitly. its only when you create String object as String literal e.g. String s = "Test" it put the String in pool.

Admin
Admin

Posts : 131
Join date : 2011-08-16

https://codefornongeek.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum