We would like to know how to get Differences Between Two Integer Collection.
import java.util.Arrays; import java.util.LinkedList; import java.util.List; /*from ww w . ja v a2 s . com*/ public class Main { public static void main(String[] args) { List<Integer> first = Arrays.asList(2, 3, 4, 5); List<Integer> second = Arrays.asList(1, 3, 4, 6); List<Integer> missing = new LinkedList<Integer>(); List<Integer> added = new LinkedList<Integer>(second); for (Integer i : first) { if (!added.remove(i)) { missing.add(i); } } System.out.println("Missing ints in second: " + missing); System.out.println("New ints in second: " + added); } }
The code above generates the following result.