Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #30510
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: toArray().. shallow or deep copies |
| Date | 2014-12-08 08:04 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <m647kr$k7n$1@dont-email.me> (permalink) |
| References | <2014120801015257172-nothing@invalid> |
On 12/8/2014 1:01 AM, Jason S. wrote:
> Question... when using the toArray() method on a Collection, are the
> references in the array a shallow or deep copy of the objects in the
> Collection?
"Shallow" and "deep" aren't rigorously defined, so I'll try to
answer without using those terms ...
The Collection contains reference values that (if non-null) point
to objects. The array generated by toArray() contains copies of those
reference values, pointing to the same objects. Once created, the
Collection and the array are independent in the sense that modifying
one has no effect on the other. If the pointed-to objects are mutable,
modifications made via the array's references are visible via the
Collection's references, and vice versa.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
toArray().. shallow or deep copies Jason S. <nothing@invalid> - 2014-12-08 01:01 -0500 Re: toArray().. shallow or deep copies Amit Sharma <kumaramitsharma92@gmail.com> - 2014-12-08 02:09 -0800 Re: toArray().. shallow or deep copies Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-12-08 08:04 -0500 Re: toArray().. shallow or deep copies Arne Vajhøj <arne@vajhoej.dk> - 2014-12-08 20:57 -0500 Re: toArray().. shallow or deep copies Jason Savlov <email@domain.com> - 2014-12-09 00:36 -0500
csiph-web