Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #30510

Re: toArray().. shallow or deep copies

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: toArray().. shallow or deep copies
Date Mon, 08 Dec 2014 08:04:43 -0500
Organization A noiseless patient Spider
Lines 19
Message-ID <m647kr$k7n$1@dont-email.me> (permalink)
References <2014120801015257172-nothing@invalid>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Mon, 8 Dec 2014 13:04:27 +0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="bd4e1cba8d8592bec5d5ed9e4537fbfd"; logging-data="20727"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7YAL+P4Tz0Y6jtLiA7DXt"
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0
In-Reply-To <2014120801015257172-nothing@invalid>
Cancel-Lock sha1:fYFbxQENsYyXNvut0XjqRNS2ETs=
Xref csiph.com comp.lang.java.programmer:30510

Show key headers only | View raw


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


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