About Question com.enthuware.ets.scjp.v6.2.426 :
Moderator: admin
About Question com.enthuware.ets.scjp.v6.2.426 :
I understood that strings were put in the string pool and therefore not GC'd?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.426 :
Not all strings fall into that category. If you create a string using new e.g. new String("xyz"), there are actually two string objects created, one instantiated in a string pool (which cannot be GCed) and another one in the heap (which can be GCed).
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Fri Dec 21, 2012 9:51 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.426 :
Hi, we should not consider the "" as collectible?
thanks.
thanks.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.426 :
That depends on whether it is a literal or now.adrianoribeiro wrote:Hi, we should not consider the "" as collectible?
thanks.
String s = ""; //not collectible.
String s = new String(""); //collectible.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Bing [Bot] and 228 guests