Java Collection Concatenate concat(final Collection... collections)

Here you can find the source of concat(final Collection... collections)

Description

Concatenates all the given collections together (order is conserved).

License

Apache License

Parameter

Parameter Description
collections The collection(s).

Return

The given collections concatenated together.

Declaration

@SafeVarargs
public static <T> List<T> concat(final Collection<T>... collections) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    /**//  ww w . ja va 2  s. c  o  m
     * Concatenates all the given {@code collections} together (order is conserved).
     * <p/>
     * <pre>
     * concat({4,5}, {1,6}, {7,9}) -> {4,5,1,6,7,9}
     * concat({4,5}, null, {7,9}) -> {4,5,7,9}
     * </pre>
     *
     * @param collections
     *         The collection(s).
     * @return The given {@code collections} concatenated together.
     */
    @SafeVarargs
    public static <T> List<T> concat(final Collection<T>... collections) {

        final List<T> concatenation = new ArrayList<T>();

        for (final Collection<T> collection : collections) {
            if (collection != null) {
                concatenation.addAll(collection);
            }
        }

        return concatenation;
    }
}

Related

  1. concat(Collection pieces, String delim)
  2. concat(Collection a, Collection b)
  3. concat(Collection a, int offset, String sep, String start, String end)
  4. concat(Collection first, Collection second)
  5. concat(Collection... collections)
  6. concat(final Collection... collections)
  7. concat(String separator, Collection args)
  8. concat(String[] first, Collection second)
  9. concatCollection(Collection collection)