Sets operations in Java

Forums:

HashSet<Integer> first = new HashSet<Integer>(Arrays.asList(1, 2, 3));
HashSet<Integer> second = new HashSet<Integer>(Arrays.asList(3, 4, 5));

first.addAll(second);
//first is { 1, 2, 3, 4, 5 }

first.removeAll(second);
//first is { 1, 2 }

first.retainAll(second);
//first is { 3 }