Java tutorial
//package com.java2s; import java.util.HashSet; import java.util.List; import java.util.Set; public class Main { public static void compareList(List<? extends Object> origin, List<? extends Object> current, List<Object> added, List<Object> removed) { if (origin == null) { if (current != null) { added.addAll(current); } return; } if (current == null) { if (origin != null) { removed.addAll(origin); } return; } Set<Object> originSet = new HashSet<Object>(origin); for (Object eachValue : current) { if (!originSet.remove(eachValue)) { added.add(eachValue); } } removed.addAll(originSet); } }