Here you can find the source of combineAndRemoveDuplicates(Collection
public static <T> Collection<T> combineAndRemoveDuplicates(Collection<T> collection1, Collection<T> collection2)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; public class Main { public static <T> Collection<T> combineAndRemoveDuplicates(Collection<T> collection1, Collection<T> collection2) { Collection<T> merged; try {//from w ww . j av a 2s. c o m merged = collection1.getClass().newInstance(); } catch (Exception ex) { merged = new ArrayList<T>(); } merged.addAll(collection1); merged.addAll(collection2); Collection<T> output; try { output = collection1.getClass().newInstance(); } catch (Exception ex) { output = new ArrayList<T>(); } for (T val : merged) { if (!output.contains(val)) { output.add(val); } } return output; } }