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

How many String objects created?

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


Source: Voodoo mock questions




Please give me tips how to count object!



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



11. public String createStrings() {
12. String ss = �Albert�;// Albert *1
13. ss = ss + �72�;// "72" *2 , Albert72 *3
14. ss = ss.substring(2, 5);// ber *4
15. ss = ss.toUpperCase(); // BER *5
16. return ss.toString(); // BER *6
17. }



6 Objects
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will not find such twisted questions on the exam
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think there are 5 string objects in this question.
 
Arad Chear
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I think there are 5 string objects in this question.



what about String toString() method ?

its create String represent the state of the Object
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with shreedevi here, I think only 5 objects are created.

I don't think the call to ss.toString(); creates another String object. API says:

"This object (which is already a string!) is itself returned"
 
shreedevi Devi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Eisa Ayed:


what about String toString() method ?

its create String represent the state of the Object




11. public String createStrings() {
12. String ss = �Albert�; ===>1
13. ss = ss + �72�; ==>2
14. ss = ss.substring(2, 5); ==>3
15. ss = ss.toUpperCase(); ==>4
16. return ss.toString(); ==5
17. }

ss = ss + �72�; willl create only one string object.Because internally it creats StringBuffer.
For eg.

StringBuffer sBuf = new StringBuffer(ss)
ss.append("72')
ss.toString() which will create one String object only.

Thanks
 
Let's go to the waterfront with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic