File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Android Security Essentials Live Lessons this week in the Android 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How many String objects created
 
Similar Threads
copying directories thru java code
How many objects are Garbage collected.Explain
Help: Basics of Thread
String literals??
Are string literals garbage collected?