public class MapCollectors
extends java.lang.Object
Class provides static factory methods to create Collector instances to transform streams into maps.
Main differences from methods are:
Collectors.toMap
Map.merge(Object, Object, java.util.function.BiFunction) method and instead
performs all merging "manually", using "containsKey", "get", and "put". Note! This means that
both elements of a merging function might be nulls!
replacingMerger()
Also there're collector factories specifically for stream of map entries: toMap() or toMap(Supplier)
| Modifier and Type | Method and Description |
|---|---|
static <V> java.util.function.BinaryOperator<V> |
replacingMerger()
Creates a binary operator that always returns second argument.
|
static <K,V> java.util.stream.Collector<java.util.Map.Entry<K,V>,?,java.util.Map<K,V>> |
toMap()
Create new collector that will collect stream of map entries into a default map.
|
static <T,K,V> java.util.stream.Collector<T,?,java.util.Map<K,V>> |
toMap(java.util.function.Function<? super T,? extends K> keyMapper,
java.util.function.Function<? super T,? extends V> valueMapper)
Map each element of the a stream into key/value pair by specified functions.
|
static <T,K,V> java.util.stream.Collector<T,?,java.util.Map<K,V>> |
toMap(java.util.function.Function<? super T,? extends K> keyMapper,
java.util.function.Function<? super T,? extends V> valueMapper,
java.util.function.BinaryOperator<V> mergeFunction)
Map each element of the a stream into key/value pair by specified functions.
|
static <T,K,V,M extends java.util.Map<K,V>> |
toMap(java.util.function.Function<? super T,? extends K> keyMapper,
java.util.function.Function<? super T,? extends V> valueMapper,
java.util.function.BinaryOperator<V> mergeFunction,
java.util.function.Supplier<M> mapSupplier)
Map each element of the a stream into key/value pair by specified functions.
|
static <T,K,V,M extends java.util.Map<K,V>> |
toMap(java.util.function.Function<? super T,? extends K> keyMapper,
java.util.function.Function<? super T,? extends V> valueMapper,
java.util.function.Supplier<M> mapSupplier)
Map each element of the a stream into key/value pair by specified functions.
|
static <K,V,M extends java.util.Map<K,V>> |
toMap(java.util.function.Supplier<M> mapSupplier)
Create new collector that will collect stream of map entries into a map provided by the specified supplier.
|
public static <K,V> java.util.stream.Collector<java.util.Map.Entry<K,V>,?,java.util.Map<K,V>> toMap()
toMap(Supplier)public static <K,V,M extends java.util.Map<K,V>> java.util.stream.Collector<java.util.Map.Entry<K,V>,?,M> toMap(java.util.function.Supplier<M> mapSupplier)
toMap()public static <T,K,V> java.util.stream.Collector<T,?,java.util.Map<K,V>> toMap(java.util.function.Function<? super T,? extends K> keyMapper,
java.util.function.Function<? super T,? extends V> valueMapper)
public static <T,K,V> java.util.stream.Collector<T,?,java.util.Map<K,V>> toMap(java.util.function.Function<? super T,? extends K> keyMapper,
java.util.function.Function<? super T,? extends V> valueMapper,
java.util.function.BinaryOperator<V> mergeFunction)
public static <T,K,V,M extends java.util.Map<K,V>> java.util.stream.Collector<T,?,M> toMap(java.util.function.Function<? super T,? extends K> keyMapper,
java.util.function.Function<? super T,? extends V> valueMapper,
java.util.function.Supplier<M> mapSupplier)
public static <T,K,V,M extends java.util.Map<K,V>> java.util.stream.Collector<T,?,M> toMap(java.util.function.Function<? super T,? extends K> keyMapper,
java.util.function.Function<? super T,? extends V> valueMapper,
java.util.function.BinaryOperator<V> mergeFunction,
java.util.function.Supplier<M> mapSupplier)
public static <V> java.util.function.BinaryOperator<V> replacingMerger()