List of usage examples for java.util Collection stream
default Stream<E> stream()
From source file:Main.java
public static String join(Collection<?> objects, String delimiter) { return objects.stream().map(String::valueOf).collect(joining(delimiter)); }
From source file:Main.java
public static <T> List<T> filterByType(Collection<? super T> objects, Class<T> type) { return objects.stream().filter(type::isInstance).map(type::cast).collect(toList()); }
From source file:Main.java
public static <T> List<T> filter(Collection<? extends T> xs, Predicate<? super T> predicate) { return xs.stream().filter(predicate).collect(toList()); }
From source file:Main.java
public static String collectionToString(Collection<?> collection) { return collection.stream().map(String::valueOf).collect(Collectors.joining(",", "(", ")")); }
From source file:Main.java
public static <A, B> List<B> map(Collection<? extends A> xs, Function<? super A, ? extends B> mapper) { return xs.stream().map(mapper).collect(toList()); }
From source file:Main.java
/** * Extract attribute from objects in collection and store them in array and * return./*from ww w . j a va2 s . co m*/ * * @param entities * @param keyMapper * @param arr * @return */ public static <T, K> K[] toArray(Collection<T> entities, Function<T, K> keyMapper, K[] arr) { return entities.stream().map(keyMapper).toArray(size -> arr); }
From source file:Main.java
public static <K, V> Map<K, V> asMap(Function<V, K> keySuppler, Collection<V> values) { Map<K, V> map = new HashMap<>(); values.stream().forEach(v -> map.put(keySuppler.apply(v), v)); return map;/* w w w .j ava 2 s.com*/ }
From source file:Main.java
/** * Joins 2 collections into one list.//from w w w . jav a 2s . com * * @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 String collectionToString(Collection<?> collection) { return collection.stream().map(String::valueOf).collect(joining(",", "(", ")")); }
From source file:Main.java
/** * Returns the given collection as stream. * * @param <T>/*w w w . jav a 2 s .c o m*/ * the generic type * @param source * the source * @param parallel * <code>true</code> if the stream should be a parallel stream * @return the stream */ public static <T> Stream<T> asStream(Collection<T> source, boolean parallel) { return parallel ? source.parallelStream() : source.stream(); }