Example usage for java.util List addAll

List of usage examples for java.util List addAll

Introduction

In this page you can find the example usage for java.util List addAll.

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).

Usage

From source file:Main.java

public static <T> List<T> listWith(T... values) {
    List<T> list = new ArrayList<T>();
    list.addAll(Arrays.asList(values));
    return list;//from w  w  w . j  a  va2 s  .c o  m
}

From source file:Main.java

public static <T> List<T> concat(Collection<T> list1, Collection<T> list2) {
    List<T> result = new ArrayList<>(list1);
    result.addAll(list2);

    return result;
}

From source file:Main.java

public static <T> List<T> addToList(List<T> list, T a) {
    List<T> newlist = newEmptyList();
    newlist.addAll(list);
    newlist.add(a);//from  w  w w .  j a v  a 2s.c  om
    return newlist;
}

From source file:Main.java

public static <T> List<T> setToList(Set<T> set) {
    List<T> list = new ArrayList<T>(set.size());
    list.addAll(set);
    return list;//from   w  w w  .jav  a  2s . com
}

From source file:Main.java

public static List<Field> getDeclaredFields(Class<?> cls) {
    List<Field> list = new ArrayList<>();
    list.addAll(Arrays.asList(cls.getDeclaredFields()));
    if (!cls.getSuperclass().getName().equals(Object.class.getName())) {
        list.addAll(getDeclaredFields(cls.getSuperclass()));
    }/*www.  jav a  2  s .  c om*/
    return list;
}

From source file:Main.java

public static List<String> toStringList(Set<String> collection) {
    List<String> _list = new ArrayList<String>();
    _list.addAll(collection);

    return _list;
}

From source file:Main.java

public static <T> List<T> takeLast(List<T> list, int length) {
    if (list.size() > length) {
        int fromIndex = Math.max(0, list.size() - length);
        int toIndex = list.size();
        List<T> newList = new ArrayList<T>();
        newList.addAll(list.subList(fromIndex, toIndex));
        return newList;
    }//from  w  w  w .  ja  va 2  s  .c om
    return list;
}

From source file:Main.java

/**
 * Convert an array to a list/*  w ww  .j  ava  2s  .co  m*/
 * @param array an array
 * @return List
 */
public static <T> List<T> arrayToList(T array[]) {
    if (array != null) {
        List<T> list = new ArrayList<>();
        list.addAll(Arrays.asList(array));
        return list;
    }
    return null;
}

From source file:Main.java

public static <T> List<T> symmetryDifference(List<T> a, List<T> b) {
    List<T> result = difference(a, b);
    result.addAll(difference(b, a));
    return result;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> List<T> merge(Collection<T> c1, Collection<T> c2) {
    List list = new ArrayList(c1.size() + c2.size());
    list.addAll(c1);
    list.addAll(c2);/*from w ww.java 2s . c o m*/
    return list;
}