my dog learned polymorphism
The moose likes Beginning Java and the fly likes collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "collections" Watch "collections" New topic


Raj chiru
Ranch Hand

Joined: Aug 12, 2008
Posts: 142
List L1 contains {A,B,C,D,E} objects and L2 contain {C,E,F,G,H} but i want List L3 contain union?
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 44022
Welcome to JavaRanch

For set union you probably want a Set, not a List. The most popular type of Set is probably the HashSet.

Look through the Set interface API documentation and you will find methods which mimic set union, set intersection and set difference. You can pass one List to the HashSet constructor, then use the appropriate method to do a set union. Go through the methods and you will find the right methods.

Hint: Use ctrl-F "union" or look for methods with "All" in their names. There are similar methods in the List interface, but they are "optional" so you would have to check your implementation to make sure they are supported.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: collections
It's not a secret anymore!