aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes STring object Creation 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 "STring object Creation" Watch "STring object Creation" New topic
Author

STring object Creation

nikhil nandu
Greenhorn

Joined: Jan 10, 2001
Posts: 4
String s1 = "ABCDEF";
String s2 = s1.substring(0, 3);
String s3 = s1.substring(3, 6);
String s4 = s2.toUpperCase() + s3.toLowerCase();
How many String objects creates this code?
A. 4
B. 5
C. 6
D. StringIndexOutOfBoundsException is thrown
I think ans is 4.Please correct me if i m rong.
Thanks.
sunilkumar ssuparasmul
Ranch Hand

Joined: Dec 13, 2000
Posts: 142
String s1 = "ABCDEF";
String s2 = s1.substring(0, 3);
String s3 = s1.substring(3, 6);
String s4 = s2.toUpperCase() + s3.toLowerCase();
How many String objects creates this code?

i guess 5 objects bcos s1,s2,s3,s4 are all obvious but s3.toLowerCase returns a new object "def" . so on the whole 5 objects r created . correct me if i am wrong.


------------------
"Winners don't do different things
They do things differently"


"Winners don't do different things<br /> They do things differently"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: STring object Creation