| Author |
String Test
|
Sarath Koiloth Ramath
Ranch Hand
Joined: May 07, 2008
Posts: 52
|
|
How many String objects will be created when this method is invoked?and how ? Thanks in advance
|
J 4 Java
|
 |
Mustafa Musaji
Ranch Hand
Joined: May 03, 2008
Posts: 52
|
|
I'm having trouble with String creations also but I think the above code will create 5 String objects. They are: Fred 47 Fred47 ed4 ED4 Please correct me if I am wrong. What do you think the answer is? [ May 30, 2008: Message edited by: Mustafa Musaji ]
|
SCJP 5.0 - Passed
|
 |
niveditha ramana
Greenhorn
Joined: May 31, 2008
Posts: 6
|
|
String s = "Fred"; s = s + "47"; s = s.substring(2, 5); s = s.toUpperCase(); i think only four objects were created 1. "Fred" 2. s now refers the object s+"47" ->"Fred47" 3. "ed4" 4. lastly object "ED4"
|
with regards<br />niveditha<br /> <br />"The pessimist borrows trouble; the optimist lends encouragement"<br />- William Arthur Ward
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
|
I think this same question has come up before; please quote where you got the question from. And remembering what was discussed when it came up before, the answer is simple: you have both got it wrong. Read the question carefully and give the correct answer.
|
 |
Dinesh Tahiliani
Ranch Hand
Joined: Aug 06, 2007
Posts: 486
|
|
This question is from Kathy and sierra book i think answer is 2 string objects created 1. String s ="fred" 2. s=s+"47" please correct me if i am wrong..
|
Thanks<br />Dinesh
|
 |
Yaroslav Ashurin
Greenhorn
Joined: Apr 25, 2008
Posts: 19
|
|
Hey, Sarath, what's up. Please check the thread: http://www.coderanch.com/t/410223/java/java/String-objects
|
SCJP 1.5
|
 |
niveditha ramana
Greenhorn
Joined: May 31, 2008
Posts: 6
|
|
thank you Yaroslav Ashurin i got it clear. thanks lot for Campbell Ritchie
|
 |
 |
|
|
subject: String Test
|
|
|