File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How Many Objects?

 
Prash Singh
Ranch Hand
Posts: 103
jQuery Netbeans IDE Notepad
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,


In the following statement how many Objects will be created?


My guess is two.
One is StringBuilder object i.e sb and second is String object "abc".
Am I right?

Please correct me, if I am wrong?

Thanks in Advance.
 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are right here 2 objects and one reference variable is created.
 
Peter Taucher
Ranch Hand
Posts: 174
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question to the pros around: If the internal array 'value' of StringBuilder was recreated in method expandCapacity() would that make it three Objects? Of course, it isn't as the constructor creates a big enough array ... but using the parameterless constructor and then appending a longer String object should result in a new backing array. Would in Java that be considered as Object as well ... or if speaking in term of Objects the internal representations are never minded?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Internal representations must be ignored by definition--they're internal, and we wouldn't necessarily have any way of knowing what is or isn't created.

If you create a LinkedHashSet should we count the List that's created? What about objects created for garbage collection management, and so on?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic