• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

STring object Creation

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic