Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.function.Consumer; public class Main { public static <T> void diff(Collection<T> from, Collection<T> to, Consumer<? super T> foreachAdd, Consumer<? super T> foreachRemove) { List<T> added = new ArrayList<>(to); added.removeAll(from); added.forEach(foreachAdd); List<T> removed = new ArrayList<>(from); removed.removeAll(to); removed.forEach(foreachRemove); } }