File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
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: 45429
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 agree. Here's the link:
subject: collections
It's not a secret anymore!