• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

String Doubt

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends,



As String are immutable, everytime we modify a String a new String is created..Considering the fact..can anyone tell

how many String objects will be created when go() method is invoked..

I guess...5 as follows..."HAR","89","HAR89","ar8","AR8"..
What do you think..?



Can anyone please give their suggestions on the above problem.Thank you in advance.

Regards,
Hardik.S.Raja

[ June 10, 2007: Message edited by: Hardik Raja ]

[ June 10, 2007: Message edited by: Hardik Raja ]
[ June 10, 2007: Message edited by: Hardik Raja ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I cannot see where "har" comes from.
 
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Strictly speaking, only 3 objects will be created when invoking the method.

It is true that there are 5 String objects involved: "HAR", "89", "HAR89", "AR8" and "ar8", but only three of them will be created during invokation of the go() method: "HAR89", "AR8" and "ar8".

The reason is that objects in the String literal pool ("HAR" and "89" in this case) are created when the class is loaded, so strictly speaking those String objects will already exist when you invoke go().
[ June 10, 2007: Message edited by: Sergio Tridente ]
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, its totally 5 objects. Of them 3 got created with the invokation of the go() method.


I guess...5 as follows..."HAR","89","HAR89","har","AR8"..
What do you think..?



I too dont understand where had this "har" come from.
 
Hardik Raja
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya I made a mistake....there will be no "har"....there will be "ar8"..

I have edited my first message.....
 
no wonder he is so sad, he hasn't seen this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic