• Post Reply Bookmark Topic Watch Topic
  • New Topic

Combine two Vectors with distinct values  RSS feed

 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone!
Not sure if I should be posting this message here or in the Advanced, but I thought I would start here first.
Can someone please let me know if it's at all possible to combine two vectors so that the results are distinct values???
Any help is much appreciated!
-Shannon
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way to do it: create a Set object (say a java.util.HashSet) then use addAll() to add all the members of each Vector to the Set. The Set now contains all the unique elements. You can then construct a new Vector using the Set as a constructor argument (or empty one of the input Vectors out and use addAll to add the Set's contents.)
 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest,
FANTASTIC! I thought I was hopeless! Thank you so much!!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!