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 List<String> makeList(String[] array) {
    List<String> result;
    if (array != null) {
        result = new ArrayList<String>(array.length);
        result.addAll(Arrays.asList(array));
    } else {/*from  w  w w. java  2s  . c  o m*/
        result = null;
    }
    return result;
}

From source file:Main.java

/**
 * Flattens the provided list into a single list.
 * //  ww  w. jav  a 2  s  .c o  m
 * @param lists
 * @return
 */
public final static <V> List<V> flatten(final List<List<V>> lists) {

    int size = 0;

    for (final List<V> list : lists) {
        size += list.size();
    }

    final List<V> res = new ArrayList<V>(size);

    for (final List<V> list : lists) {
        res.addAll(list);
    }

    return res;

}

From source file:Main.java

/**
 * @param collection to collect extracted values from
 * @param extractor to transform items of collection to collections to combine
 * @param <E> the original container type
 * @param <T> the extracted item type
 * @return the extracted items in a single list
 *//*w  ww .jav  a  2s .  c o  m*/
public static <E, T, C extends Collection<T>> List<T> collect(Collection<E> collection,
        Function<E, C> extractor) {
    List<T> results = new ArrayList<T>();
    for (E item : collection) {
        results.addAll(extractor.apply(item));
    }
    return results;
}

From source file:Main.java

public static <T> List<T> joinList(List<T>... lists) {
    List<T> list = new ArrayList<T>();
    if (lists != null) {
        for (List<T> l : lists) {
            list.addAll(l);
        }// w w  w.j  a  va 2  s  .c  o  m
    }
    return list;
}

From source file:Main.java

/**
 * Concatenate the collection of lists passed as argument into a new array list.
 * @param lists//from  w w w  .ja va2s .c om
 * @param <T>
 * @return
 */
public static <T> List<T> concat(Collection<? extends Collection<T>> lists) {
    int size = 0;
    for (Collection<T> list : lists) {
        size += list.size();
    }
    List<T> result = new ArrayList<T>(size);
    for (Collection<T> list : lists) {
        result.addAll(list);
    }
    return result;
}

From source file:Main.java

private static void getIndexSublist(int numbers, int length, List<List<Integer>> result) {

    List<List<Integer>> results = new ArrayList<>();
    results.addAll(result);

    if (result.get(0).size() == length) {
        return;/* www  . ja  va 2  s. c om*/
    }

    result.clear();
    for (List<Integer> one : results) {

        for (int i = 1; i < numbers; i++) {
            if (i > one.get(one.size() - 1)) {
                ArrayList<Integer> temp = new ArrayList<Integer>();
                temp.addAll(one);
                temp.add(i);
                result.add(temp);
            }
        }
    }
    getIndexSublist(numbers, length, result);
}

From source file:Main.java

public static <V> List<V> uniteCollections(Collection<? extends Collection<V>> values) {
    if (isEmpty(values)) {
        return Collections.emptyList();
    }//from   w  w  w.  j  a  v a  2s  .c  om
    List<V> copy = new ArrayList<V>();
    for (Collection<V> collection : values) {
        copy.addAll(collection);
    }
    return copy;
}

From source file:au.org.ala.delta.delfor.DirectivesUtils.java

public static List<Directive> mergeAllDirectives() {

    List<Directive> allDirectives = new ArrayList<Directive>();
    allDirectives.addAll(Arrays.asList(ConforDirType.ConforDirArray));
    addUniqueDirectives(KeyDirType.KeyDirArray, allDirectives);
    addUniqueDirectives(DistDirType.DistDirArray, allDirectives);
    addUniqueDirectives(IntkeyDirType.IntkeyDirArray, allDirectives);

    return allDirectives;
}

From source file:com.baifendian.swordfish.common.job.struct.node.BaseParam.java

/**
 * @param resourceInfos// w w w .  jav  a  2 s . c  o  m
 * @param resFiles
 */
public static void addProjectResourceFiles(List<ResourceInfo> resourceInfos, List<String> resFiles) {
    if (CollectionUtils.isNotEmpty(resourceInfos)) {
        resFiles.addAll(resourceInfos.stream().filter(p -> p.isProjectScope()).map(p -> p.getRes())
                .collect(Collectors.toList()));
    }
}

From source file:com.spotify.echoprintserver.nativelib.Util.java

public static List<Integer> sortedDistinct(List<Integer> seq) {
    Set<Integer> codeSet = new TreeSet<Integer>();
    codeSet.addAll(seq);/*from   ww w  .j  a v a 2 s .  co m*/
    List<Integer> uniqueSortedCodeSet = new ArrayList<Integer>();
    uniqueSortedCodeSet.addAll(codeSet);
    Collections.sort(uniqueSortedCodeSet);
    return uniqueSortedCodeSet;
}