Here you can find the source of mergeCollections(Collection
@SafeVarargs public static <T> List<T> mergeCollections(Collection<T>... inCollections)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { @SafeVarargs public static <T> List<T> mergeCollections(Collection<T>... inCollections) { return addCollections(false, inCollections); }//from w ww .ja v a2s . c o m @SafeVarargs public static <T> List<T> addCollections(Collection<T>... inCollections) { return addCollections(true, inCollections); } @SafeVarargs public static <T> List<T> addCollections(boolean inAddDuplicates, Collection<T>... inCollections) { final List<T> theList = new ArrayList<T>(); if (inCollections != null) { for (Collection<T> aCollection : inCollections) { if (aCollection != null) { for (T anItem : aCollection) { if (!inAddDuplicates && theList.contains(anItem)) { continue; } theList.add(anItem); } } } } return theList; } }