Possible Duplicate:
Java Compare Two Lists
If I have two ordered sequences of numbers (I have a lot of flexibility here, and could put my data in a list, set, array, etc.), what's the most efficient way to go about extracting the matches? For example, if I have:
[1, 2, 4, 6, 9]
and [2, 3, 4]
, I would like to return [2, 4]
.
There are obviously lots of ways to go about this; I'm curious what the most efficient way is.