• Post Reply Bookmark Topic Watch Topic
  • New Topic

Comparing elements in a sets?  RSS feed

 
Bob Zoloman
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have two different sets

set a: [14, 2, 30]
set b: [25, 19, 2]

how can I figure out which elements in one set has elements in another set, and print that element out? Any help is appreciated, thanks.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean how do you find out the common elements between the Sets?

If you look at the API docs for Set, any class that implements Set must implement a method called retainAll.

Look at the API docs for that method and you should see how you can use it.
 
Bob Zoloman
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that method is exactly what I needed.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!