Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Programmer > Re: is an objec...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 6 Topic 52628 of 55513
Post > Topic >>

Re: is an object deep-copied when added to a collection?

by ptomblin+netnews@[EMAIL PROTECTED] (Paul Tomblin) May 11, 2008 at 02:27 AM

In a previous article, "Peter Duniho" <NpOeStPeAdM@[EMAIL PROTECTED]
> said:
>"yes", that's not the answer to the question in the subject.  Objects  
>_aren't_ "deep copied" when added to a collection.  They aren't even  
>"shallow copied".  Only the reference to the object is copied to the  
>collection.  The object isn't copied at all, deep or otherwise.

The great thing about that is that the cost of adding an object to a
collection or map is pretty minuscule (probably only 4 or 8 bytes).  So if
you might need to access the same object in two different orders, it's not
a big deal to make two TreeSets with different Comparators, rather than
re-sorting the same collection every time you need it in a different
order, or having multiple Maps with different keys.


-- 
Paul Tomblin <ptomblin@[EMAIL PROTECTED]
> http://blog.xcski.com/
"Dad, I left my heart up there."
    -- Francis Gary Powers after his first flight (age 14)
 




 6 Posts in Topic:
is an object deep-copied when added to a collection?
lucia.roibal@[EMAIL PROTE  2008-05-10 11:07:15 
Re: is an object deep-copied when added to a collection?
Eric Sosman <esosman@[  2008-05-10 14:18:20 
Re: is an object deep-copied when added to a collection?
"Peter Duniho"   2008-05-10 11:40:12 
Re: is an object deep-copied when added to a collection?
ptomblin+netnews@[EMAIL P  2008-05-11 02:27:51 
Re: is an object deep-copied when added to a collection?
Mark Space <markspace@  2008-05-10 11:39:57 
Re: is an object deep-copied when added to a collection?
Andrea Francia <andrea  2008-05-11 01:22:25 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 20:10:46 CST 2008.