Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #30505 > unrolled thread
| Started by | Jason S. <nothing@invalid> |
|---|---|
| First post | 2014-12-08 01:01 -0500 |
| Last post | 2014-12-09 00:36 -0500 |
| Articles | 5 — 5 participants |
Back to article view | Back to comp.lang.java.programmer
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
| From | Jason S. <nothing@invalid> |
|---|---|
| Date | 2014-12-08 01:01 -0500 |
| Subject | toArray().. shallow or deep copies |
| Message-ID | <2014120801015257172-nothing@invalid> |
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? Thanks
[toc] | [next] | [standalone]
| From | Amit Sharma <kumaramitsharma92@gmail.com> |
|---|---|
| Date | 2014-12-08 02:09 -0800 |
| Message-ID | <dfc9a8c2-d114-4a8c-93e2-88d5ef8c654a@googlegroups.com> |
| In reply to | #30505 |
Some operations on array are more efficient than that of collection. Like a collecton provides a specified order of elements the using toArray() we can convert it in array and use various operations like reversing the array. Instead of all these things searching and sorting are more efficient in case of array. And mostly we use toArray() method in case of junit framework to test our method. We can't compare two lists in junit efficiently so first convert them in form of arrays and use arrayEquals(array1, array2) method.
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2014-12-08 08:04 -0500 |
| Message-ID | <m647kr$k7n$1@dont-email.me> |
| In reply to | #30505 |
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
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2014-12-08 20:57 -0500 |
| Message-ID | <54865721$0$299$14726298@news.sunsite.dk> |
| In reply to | #30505 |
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. Arne
[toc] | [prev] | [next] | [standalone]
| From | Jason Savlov <email@domain.com> |
|---|---|
| Date | 2014-12-09 00:36 -0500 |
| Message-ID | <2014120900363085472-email@domaincom> |
| In reply to | #30505 |
Thanks for the help, guys. Answers helped me understand the assignment I was working on. Cheers!
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web