Java Collection Merge mergeCollections(Collection... inCollections)

Here you can find the source of mergeCollections(Collection... inCollections)

Description

merge Collections

License

Open Source License

Declaration

@SafeVarargs
    public static <T> List<T> mergeCollections(Collection<T>... inCollections) 

Method Source Code

//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;
    }
}

Related

  1. merge(final Collection values)
  2. merge(J just, Collection justs)
  3. mergeArrayIntoCollection(T[] array, Collection collection)
  4. mergeCollection( final Collection col1, final Collection col2)
  5. mergeCollection(Collection a, Collection b)