List of usage examples for java.util.stream Collectors toConcurrentMap
public static <T, K, U> Collector<T, ?, ConcurrentMap<K, U>> toConcurrentMap( Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper, BinaryOperator<U> mergeFunction)
From source file:Main.java
public static void main(String[] args) { Map<Employee.Gender, Long> countByGender = Employee.persons().stream().collect(Collectors .toConcurrentMap(Employee::getGender, p -> 1L, (oldCount, newCount) -> newCount + oldCount)); System.out.println(countByGender); }
From source file:Main.java
public static void main(String[] args) { List<String> terms = Arrays.asList("this", "is", "is", "a"); Map<String, Integer> result = terms.parallelStream().flatMap(s -> Arrays.asList(s.split(" ")).stream()) .collect(Collectors.toConcurrentMap(w -> w.toLowerCase(), w -> 1, Integer::sum)); System.out.println(result);//from w w w . j av a 2 s . c o m }
From source file:ru.anr.base.BaseParent.java
/** * A short-cut function to simplify the process of building a map from a * collection when there can be non-unique keys. * /* www . jav a 2s . c o m*/ * @param collection * An original collection * @param keyMapper * A key mapper * @param valueMapper * A value mapper * @param mergeFunction * A function to merge values conflicting by their key * @return A new map * * @param <T> * The type of a collection item * @param <K> * Type of the map key * @param <U> * Type of the map value */ public static <T, K, U> Map<K, U> toMap(Collection<T> collection, Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper, BinaryOperator<U> mergeFunction) { return collection.stream().collect(Collectors.toConcurrentMap(keyMapper, valueMapper, mergeFunction)); }