Example usage for java.util.stream Collectors toList

List of usage examples for java.util.stream Collectors toList

Introduction

In this page you can find the example usage for java.util.stream Collectors toList.

Prototype

public static <T> Collector<T, ?, List<T>> toList() 

Source Link

Document

Returns a Collector that accumulates the input elements into a new List .

Usage

From source file:Main.java

@SafeVarargs
public static <T> List<T> unionArraysAsList(T[]... arrays) {
    return Stream.of(arrays).map(Arrays::asList).flatMap(Collection::stream).collect(Collectors.toList());
}

From source file:Main.java

public static <Key, Value> Collection<Value> filterMapValues(Map<Key, Value> map,
        Predicate<Map.Entry<Key, Value>> entryPredicate) {
    return map.entrySet().parallelStream().filter(entryPredicate).map(Map.Entry::getValue)
            .collect(Collectors.toList());
}

From source file:Main.java

public static <T> List<String> toStringsList(T[] array) {
    return Arrays.stream(array).map(x -> x.toString()).collect(Collectors.toList());
}

From source file:Main.java

public static <Key, Value> Collection<Value> filterMapValuesByKey(Map<Key, Value> map,
        Predicate<Key> keyPredicate) {
    return map.entrySet().parallelStream().filter(entry -> keyPredicate.test(entry.getKey()))
            .map(Map.Entry::getValue).collect(Collectors.toList());
}

From source file:Main.java

/**
 * Split the list and return the stream with the resultant lists.
 * @param list to be split/* w  ww  . ja va2s. c  o m*/
 * @param size of each list after splitting.
 * @param <T> type of list.
 * @return {@link List} of {@link ArrayList}s
 */
public static <T> List<List<T>> splitArrayList(final List<T> list, final int size) {
    return splitListStream(list, size).map(ArrayList::new).collect(Collectors.toList());
}

From source file:Main.java

public static <T, R> List<R> map(List<T> collection, Function<T, R> mapper) {
    return stream(collection).map(mapper).collect(Collectors.toList());
}

From source file:Main.java

/**
 * Joins 2 collections into one list.//from   w w  w.j a v  a 2 s.c o  m
 *
 * @param a Some collection
 * @param b Some other collection
 * @param <T> The type of the elements
 *
 * @return A List that contains all the elements of both collections.
 */
public static <T> List<T> join(Collection<? extends T> a, Collection<? extends T> b) {
    return Stream.concat(a.stream(), b.stream()).collect(Collectors.toList());
}

From source file:Main.java

public static <T, R> List<R> apply(List<T> list, Function<T, R> mapper) {
    return list.stream().map(mapper).collect(Collectors.toList());
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <TargetType, CurrentType> List<TargetType> cast(List<CurrentType> list,
        Class<TargetType> targetClass) {
    return list.stream().map(e -> (TargetType) e).collect(Collectors.toList());
}

From source file:Main.java

public static List<Class> scanAll(String packageName) {
    return scan(packageName).collect(Collectors.toList());
}