Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #30631
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: how do I merg two collections? |
| Date | 2015-01-05 08:57 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <m8e56s$r3g$1@dont-email.me> (permalink) |
| References | <e429296f-b008-4a89-82e5-759d26d97edd@googlegroups.com> |
On 1/5/2015 1:55 AM, Brian O'Brien wrote:
> I have two collections and I want to create a third Collection that is the union of the two collecions.
>
> //psuedo code
How do yuo pronuonce "psuedo?" :)
> Collection<String> a = "1","a", "2", "b";
> Collection<String> b = "3", "a, "4", "b";
> Collection<String> c = a + b;
> // would produce..
> "1", "a" , "2", "b", "3", "4"
>
> Is there a collection method that does this?
>
> Or must I iterate through the one of the sets and add to the other if it does not 'contain' the object?
If you want c to contain no duplicated elements and you don't
care about their "order," use a Set:
c = new HashSet<String>(a).addAll(b);
If you want to keep the a's and/or b's in their original order
(or in any defined order), or if you want to preserve duplicate a's and
duplicate b's (while eliminating b's that duplicate a's), please
describe in more detail what you're trying to accomplish.
--
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
how do I merg two collections? Brian O'Brien <brian.obrien@calgaryscientific.com> - 2015-01-04 22:55 -0800
how do I merg two collections? Lew <lewbloch@gmail.com> - 2015-01-04 23:17 -0800
Re: how do I merg two collections? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-01-05 08:57 -0500
Re: how do I merg two collections? BOB <brian.obrien@calgaryscientific.com> - 2015-01-05 08:38 -0800
Re: how do I merg two collections? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-01-05 11:52 -0500
Re: how do I merg two collections? BOB <brian.obrien@calgaryscientific.com> - 2015-01-05 13:26 -0800
Re: how do I merg two collections? Jeff Higgins <jeff@invalid.invalid> - 2015-01-05 17:15 -0500
Re: how do I merg two collections? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-01-05 17:35 -0500
Re: how do I merg two collections? Lew <lewbloch@gmail.com> - 2015-01-06 15:38 -0800
Re: how do I merg two collections? Martin Gregorie <martin@address-in-sig.invalid> - 2015-01-07 13:40 +0000
csiph-web