Java Collection Combine combine(Collection... collections)

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

Description

combine all lists into one list containing all elements.

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
public static <T> List<T> combine(Collection<?>... collections) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010-2015 BSI Business Systems Integration AG.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from w  w  w . ja  v  a 2s  .  co  m
 *     BSI Business Systems Integration AG - initial API and implementation
 ******************************************************************************/

import java.util.ArrayList;

import java.util.Collection;

import java.util.List;

public class Main {
    /**
     * combine all lists into one list containing all elements. the order of the items is preserved
     */
    @SuppressWarnings("unchecked")
    public static <T> List<T> combine(Collection<?>... collections) {
        List<T> list = new ArrayList<T>();
        if (collections != null && collections.length > 0) {
            for (Collection<?> c : collections) {
                for (Object t : c) {
                    list.add((T) t);
                }
            }
        }
        return list;
    }
}

Related

  1. combine(Collection first, Collection second)
  2. combine(Collection strings)
  3. combine(final Collection[] c)
  4. combine(String separator, Collection parts)
  5. combine(String separator, Collection stringCollection)