The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Collections framework: How to do a bag union?

Posted by Steven Tolkin on April 24, 2000 at 5:44 PM

Suppose collection b1 is [a, a, b] and collection b2 is [a, c].
Using addAll it is easy to compute "additive union", which is
[a, a, a, b, c]. But how can I compute the "bag union" (which C++ STL
calls set_union), i.e. [a, a, b, c]. In a bag union
the result contains as many instances of each element as
were in the input having the greater number.


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us