This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Test

 
Sarath Koiloth Ramath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

How many String objects will be created when this method is invoked?and how ?

Thanks in advance
 
Mustafa Musaji
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
niveditha ramana
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Yaroslav Ashurin
Greenhorn
Posts: 22
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, Sarath, what's up.

Please check the thread: http://www.coderanch.com/t/410223/java/java/String-objects
 
niveditha ramana
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you Yaroslav Ashurin
i got it clear.

thanks lot for Campbell Ritchie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic