This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How many String objects created Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How many String objects created" Watch "How many String objects created" New topic
Author

How many String objects created

allison craig
Greenhorn

Joined: Dec 19, 2003
Posts: 17
String str = new String("zyx");

Yeah, yeah, I know everybody knows this.

Is it two, one for the 'new String' and the other "zyx"?
Is there a way check the actual number of Strings created?
[ January 20, 2004: Message edited by: allison craig ]
Vin Kris
Ranch Hand

Joined: Jun 17, 2002
Posts: 154
Just as you guessed, 2 String objects. A String literal "zyx" and a String object. Latter is eligible for GC and the former isn't.
allison craig
Greenhorn

Joined: Dec 19, 2003
Posts: 17
Thanks Vin. I'm going to pretend I can read opcodes.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How many String objects created
 
Similar Threads
How many objects are Garbage collected.Explain
Help: Basics of Thread
String literals??
Are string literals garbage collected?
copying directories thru java code