This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • 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: 48454
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic