Java List Concatenate concatSuper(List collection1, List collection2)

Here you can find the source of concatSuper(List collection1, List collection2)

Description

concat Super

License

Open Source License

Declaration

public static <T> List<? extends T> concatSuper(List<? extends T> collection1, List<? extends T> collection2) 

Method Source Code

//package com.java2s;

import java.util.ArrayList;

import java.util.Collection;

import java.util.List;
import java.util.Map;

public class Main {

    public static <T> List<? extends T> concatSuper(List<? extends T> collection1, List<? extends T> collection2) {
        if (isEmpty(collection1)) {
            return collection2;
        }//from www.j  av a  2 s . c  om
        if (isEmpty(collection2)) {
            return collection1;
        }
        List<T> result = createArrayList(collection1.size() + collection2.size());
        result.addAll(collection1);
        result.addAll(collection2);
        return result;

    }

    public static boolean isEmpty(Map<?, ?> map) {
        return (map == null) || (map.size() == 0);
    }

    public static boolean isEmpty(Collection<?> collection) {
        return (collection == null) || (collection.size() == 0);
    }

    public static <E> ArrayList<E> createArrayList() {
        return new ArrayList<E>();
    }

    public static <E> ArrayList<E> createArrayList(int initialCapacity) {
        return new ArrayList<E>(initialCapacity);
    }

    public static <E> ArrayList<E> createArrayList(Collection<? extends E> collection) {
        if (collection == null) {
            return new ArrayList<E>();
        }

        return new ArrayList<E>(collection);
    }

    public static <E> ArrayList<E> createArrayList(Iterable<? extends E> iter) {

        if (iter instanceof Collection<?>) {
            return new ArrayList<E>((Collection<? extends E>) iter);
        }

        ArrayList<E> list = new ArrayList<E>();

        iterableToCollection(iter, list);

        list.trimToSize();

        return list;
    }

    public static <T, V extends T> ArrayList<T> createArrayList(V... args) {
        if (args == null || args.length == 0) {
            return new ArrayList<T>();
        }

        ArrayList<T> list = new ArrayList<T>(args.length);

        for (V v : args) {
            list.add(v);
        }

        return list;

    }

    private static <E> void iterableToCollection(Iterable<? extends E> iter, Collection<E> list) {
        if (iter == null) {
            return;
        }

        for (E element : iter) {
            list.add(element);
        }
    }
}

Related

  1. concatNodeList(List list)
  2. concatPathTokens(String root, List tokens)
  3. concatRefs(List refs)
  4. concatString(List args)
  5. concatStrings(List values, String separator)
  6. concatSynopsises( List prefixes, List ss)
  7. concatTwoList(List fromList, List toList)
  8. concatValues(List stringValues, boolean spaceSeparated)
  9. concatWithSeparator(List list, Object delimiter)