Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.Set; public class Main { public static <T> ArrayList<T> merge(Collection<T> l1, Collection<T> l2, T toRemove) { ArrayList<T> al = union(l1, l2); al.remove(toRemove); return al; } public static <T> ArrayList<T> union(Collection<T> l1, Collection<T> l2) { Set<T> s = new HashSet<>(); s.addAll(l1); s.addAll(l2); return new ArrayList<>(s); } }