Java List Combine combine(List... dests)

Here you can find the source of combine(List... dests)

Description

combine

License

Apache License

Declaration

@SuppressWarnings({ "unchecked", "varargs" })
    public static <T> List<T> combine(List<T>... dests) 

Method Source Code


//package com.java2s;
/*//from  w  ww  .  ja v  a  2s . co m
 * Copyright 2012 tetsuo.ohta[at]gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.ArrayList;

import java.util.List;

public class Main {
    @SuppressWarnings({ "unchecked", "varargs" })
    public static <T> List<T> combine(List<T>... dests) {
        List<T> list = new ArrayList<T>();
        for (List<T> dest : dests) {
            if (dest == null)
                continue;
            list.addAll(dest);
        }
        return list;
    }

    @SuppressWarnings("unchecked")
    public static <T> T[] combine(T[]... dests) {
        ArrayList<T> list = new ArrayList<T>();
        for (T[] dest : dests) {
            if (dest == null)
                continue;
            for (T e : dest)
                list.add(e);
        }
        return (T[]) list.toArray();
    }
}

Related

  1. combine(List strlist, String delimiter)
  2. combine(List tokens, String separator)
  3. combine(List a, List b)
  4. combine(List dest, Collection... src)
  5. combine(List list, int maxK)
  6. combineAfterIndexWithQuotes(List commands, String match)
  7. combineArray(List> data)
  8. combineArray(List... p)
  9. combineAsLists(Object one, Object two)