This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

STring object Creation  RSS feed

 
nikhil nandu
Greenhorn
Posts: 4
  • 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
  • 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"
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!