Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<Integer> l1 = new ArrayList<Integer>();
- l1.add(1);
- l1.add(2);
- l1.add(3);
- List<Integer> l2= new ArrayList<Integer>();
- l2.add(4);
- l2.add(2);
- l2.add(3);
- List<Integer> l3 = new ArrayList<Integer>(l2);
- l3.retainAll(l1);
- listA.retainAll(listB);
- // listA now contains only the elements which are also contained in listB.
- List<Integer> common = new ArrayList<Integer>(listA);
- common.retainAll(listB);
- // common now contains only the elements which are contained in listA and listB.
Add Comment
Please, Sign In to add comment