File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

STring object Creation

 
nikhil nandu
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 142
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic