File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Creating String Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Creating String Objects" Watch "Creating String Objects" New topic

Creating String Objects

Sumi Festus

Joined: Feb 04, 2005
Posts: 14
this was a question i stumbled upon
String x=new String("xyz");
String y="abc";
String x=x+y;

The answer says that 4 String objects are created can someone give me an explanation as to how 2 string objects are being created in the first line...
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
A String instance is created that represents the String literal, which is passed to the String(String) constructor to create yet another String instance.

Tony Morris
Java Q&A (FAQ, Trivia)
I agree. Here's the link:
subject: Creating String Objects
It's not a secret anymore!