How to get common elements from three array list optimally?
Solution 1:
This is the most concise solution, though I am not sure it is the most efficiant:
List<Integer> commonItems = new ArrayList<>(Arrays.asList(a));
commonItems.retainAll(Arrays.asList(b));
commonItems.retainAll(Arrays.asList(c));
JDK doc of List.retainAll:
Retains only the elements in this list that are contained in the specified collection (optional operation). In other words, removes from this list all of its elements that are not contained in the specified collection.