About Question com.enthuware.ets.scjp.v6.2.426 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

About Question com.enthuware.ets.scjp.v6.2.426 :

Post by ETS User »

I understood that strings were put in the string pool and therefore not GC'd?

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.426 :

Post by admin »

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.

adrianoribeiro
Posts: 1
Joined: Fri Dec 21, 2012 9:51 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.426 :

Post by adrianoribeiro »

Hi, we should not consider the "" as collectible?

thanks.

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.426 :

Post by admin »

adrianoribeiro wrote:Hi, we should not consider the "" as collectible?

thanks.
That depends on whether it is a literal or now.
String s = ""; //not collectible.
String s = new String(""); //collectible.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests