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


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

Re: how do I merg two collections?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!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: how do I merg two collections?
Date Mon, 05 Jan 2015 11:52:59 -0500
Organization A noiseless patient Spider
Lines 38
Message-ID <m8efgj$c0k$1@dont-email.me> (permalink)
References <e429296f-b008-4a89-82e5-759d26d97edd@googlegroups.com> <m8e56s$r3g$1@dont-email.me> <01479315-b953-48e1-a05c-ba926b9386c1@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Mon, 5 Jan 2015 16:52:35 +0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="bd4e1cba8d8592bec5d5ed9e4537fbfd"; logging-data="12308"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19HZsQJRpPOyGJf3ZgJ78F0"
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0
In-Reply-To <01479315-b953-48e1-a05c-ba926b9386c1@googlegroups.com>
Cancel-Lock sha1:CJ1WvNda/DOQlL1K+YDCVc9S42s=
Xref csiph.com comp.lang.java.programmer:30633

Show key headers only | View raw


On 1/5/2015 11:38 AM, BOB wrote:
> On Monday, January 5, 2015 6:57:22 AM UTC-7, Eric Sosman wrote:
>> 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.
>
> Order in not important, what is important is that the Collection NOT contain any duplicates and remains a Collection.

     Okay, use a Set.  I've shown a HashSet, which is probably the
"go to" flavor for general-purpose use, but other kinds of Set are
also available if you want their special capabilities.

-- 
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

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