使用
Collection#retainAll()。
listA.retainAll(listB);// listA now contains only the elements which are also contained in listB.
如果要避免更改受到影响listA,则需要创建一个新的更改。
List<Integer> common = new ArrayList<Integer>(listA);common.retainAll(listB);// common now contains only the elements which are contained in listA and listB.



