fork(4) download
  1. import java.util.*;
  2. import java.lang.*;
  3.  
  4. class Main
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. List<Integer> list1 = Arrays.asList(1, 2, 3, 4);
  9. List<Integer> list2 = Arrays.asList(2, 3, 4, 6, 7);
  10. List<Integer> union = new ArrayList<Integer>(list1);
  11. union.addAll(list2);
  12. List<Integer> intersection = new ArrayList<Integer>(list1);
  13. intersection.retainAll(list2);
  14. union.removeAll(intersection);
  15. for (Integer n : union) {
  16. System.out.println(n);
  17. }
  18. }
  19. }
Success #stdin #stdout 0.06s 381184KB
stdin
Standard input is empty
stdout
1
6
7