Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
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

Win a copy of The Software Craftsman this week in the Agile forum!
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)
Have you tried LearnNowOnline?
subject: Creating String Objects