Guest User

Untitled

a guest
Jul 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. List<Integer> l1 = new ArrayList<Integer>();
  2.  
  3. l1.add(1);
  4. l1.add(2);
  5. l1.add(3);
  6.  
  7. List<Integer> l2= new ArrayList<Integer>();
  8. l2.add(4);
  9. l2.add(2);
  10. l2.add(3);
  11.  
  12. List<Integer> l3 = new ArrayList<Integer>(l2);
  13. l3.retainAll(l1);
  14.  
  15. listA.retainAll(listB);
  16. // listA now contains only the elements which are also contained in listB.
  17.  
  18. List<Integer> common = new ArrayList<Integer>(listA);
  19. common.retainAll(listB);
  20. // common now contains only the elements which are contained in listA and listB.
Add Comment
Please, Sign In to add comment