• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

collections

 
Raj chiru
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic