• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

help...String object

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
This is the 1st time I am takin a ship of Java cup.
Sooo...I have some doubts. Like....
1.Concept of String Object.
e.g.
String s="rat";
String s1=s;
String s2=s1+"ban";
How many Object is Created??
according 2 me ..its 3
Ratul Banerjee.
*************T H A N K S IN A D V A N C E ****************
Round 2.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
I think only 2 objects are created. The first object is created with string s.
The line
String s1=s;
does not create any object. Here we are just creating a reference to already created object associated with string s.
The second object is created with the statement
String s2=s1+"ban";
Regards
Sandip
 
Rat Ban
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
This is the 1st time I am takin a ship of Java cup.
Sooo...I have some doubts. Like....
1.What. it would be if i change the line 3...
String s2="rat"+"ban";
Ratul Banerjee.
*************T H A N K S IN A D V A N C E ****************
Round 5.
 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it's again 2.Only 2 objects are created!!!
Bye,
Tualha Khan
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello in the first case , 3 objects are created,
String s="rat";
String s1=s;
String s2=s1+"ban";
1st object "rat"
2 object "ban"
3 object s1+"ban"=ratban.
bcos s1 is not resolved at compile time.
where as in second case it sonly 2 objects are created "rat"+"ban" here rat is resolved at compile time itselh

HTH
sunil.s


------------------
"Winners don't do different things
They do things differently"
 
Rat Ban
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Sunil,
i think sunil.s is correct.
thank u.
but Sunil,
what about StringBuffer object(the last line(appending) )
ratul Banerjee
**********T H A N K S****************


[This message has been edited by Rat Ban (edited January 20, 2001).]
 
What's that smell? Hey, sniff this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic