How do I obtain the duplicated values of two ArrayLists?

Let’s say I have 2 ArrayList of Points:

  1. (0,2)->(0,3)->(0,4)
  2. (0,2)->(0,3)->(0,6)

And I want to obtain a new list : (0,2)->(0,3)

How do I do that?

current solution

Using two foreach loops to compare the two lists, element by element. I think it’s a very inefficient way. Are there any other ways?


Source: java

Leave a Reply