wood burning stoves 2.0*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "collections" Watch "collections" New topic
Author

collections

Raj chiru
Ranch Hand

Joined: Aug 12, 2008
Posts: 141
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
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
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.
 
wood burning stoves
 
subject: collections