Modifier and Type | Method and Description |
---|---|
static <T> BinaryOperator<T> |
throwingMerger()
Returns a merge function, suitable for use in
Map.merge() or
Collectors.toMap(Function, Function, BinaryOperator) ,
which always throws IllegalStateException . |
static <K,V> Collector<Map.Entry<K,V>,?,Map<K,V>> |
toLinkedHashMap()
|
static <T,K,U> Collector<T,?,Map<K,U>> |
toLinkedHashMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends U> valueMapper)
Returns a
Collector that accumulates elements into a
LinkedHashMap whose keys and values are the result of applying the
provided mapping functions to the input elements. |
static <T,K,U> Collector<T,?,Map<K,U>> |
toLinkedHashMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends U> valueMapper,
BinaryOperator<U> mergeFunction)
Returns a
Collector that accumulates elements into a
LinkedHashMap whose keys and values are the result of applying the
provided mapping functions to the input elements. |
static <T> Collector<T,?,Set<T>> |
toLinkedHashSet()
Returns a
Collector that accumulates the input elements into a new
LinkedHashSet , in encounter order. |
static <T,K,U> Collector<T,?,Map<K,U>> |
toMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends U> valueMapper)
Returns a
Collector that accumulates elements into a Map
whose keys and values are the result of applying the provided mapping
functions to the input elements. |
static <T,K,U> Collector<T,?,Map<K,U>> |
toMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends U> valueMapper,
BinaryOperator<U> mergeFunction)
Returns a
Collector that accumulates elements into a Map
whose keys and values are the result of applying the provided mapping
functions to the input elements. |
static <T,K,U,M extends Map<K,U>> |
toMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends U> valueMapper,
BinaryOperator<U> mergeFunction,
Supplier<M> mapSupplier)
Returns a
Collector that accumulates elements into a Map
whose keys and values are the result of applying the provided mapping
functions to the input elements. |
static <T,K,U,M extends Map<K,U>> |
toMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends U> valueMapper,
Supplier<M> mapSupplier)
Returns a
Collector that accumulates elements into a Map
whose keys and values are the result of applying the provided mapping
functions to the input elements. |
static <K,V,M extends Map<K,V>> |
toMap(Supplier<M> mapSupplier)
|
public static <T> BinaryOperator<T> throwingMerger()
Map.merge()
or
Collectors.toMap(Function, Function, BinaryOperator)
,
which always throws IllegalStateException
. This can be used to
enforce the assumption that the elements being collected are distinct.T
- the type of input arguments to the merge functionIllegalStateException
public static <K,V> Collector<Map.Entry<K,V>,?,Map<K,V>> toLinkedHashMap()
K
- the type of the keyV
- the type of the valueCollector
which collects Map.Entry
elements into a
LinkedHashMap
public static <T,K,U> Collector<T,?,Map<K,U>> toLinkedHashMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)
Collector
that accumulates elements into a
LinkedHashMap
whose keys and values are the result of applying the
provided mapping functions to the input elements.T
- the type of the input elementsK
- the output type of the key mapping functionU
- the output type of the value mapping functionkeyMapper
- a mapping function to produce keysvalueMapper
- a mapping function to produce valuesCollector
which collects elements into a
LinkedHashMap
whose keys and values are the result of
applying mapping functions to the input elementspublic static <T,K,U> Collector<T,?,Map<K,U>> toLinkedHashMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction)
Collector
that accumulates elements into a
LinkedHashMap
whose keys and values are the result of applying the
provided mapping functions to the input elements.T
- the type of the input elementsK
- the output type of the key mapping functionU
- the output type of the value mapping functionkeyMapper
- a mapping function to produce keysvalueMapper
- a mapping function to produce valuesmergeFunction
- a merge function, used to resolve collisions between
values associated with the same key, as supplied to
Map.merge(Object, Object, java.util.function.BiFunction)
Collector
which collects elements into a
LinkedHashMap
whose keys are the result of applying a key
mapping function to the input elements, and whose values are the
result of applying a value mapping function to all input elements
equal to the key and combining them using the merge functionpublic static <T> Collector<T,?,Set<T>> toLinkedHashSet()
Collector
that accumulates the input elements into a new
LinkedHashSet
, in encounter order.T
- the type of the input elementsCollector
which collects all the input elements into a
LinkedHashSet
public static <K,V,M extends Map<K,V>> Collector<Map.Entry<K,V>,?,M> toMap(Supplier<M> mapSupplier)
K
- the type of the keyV
- the type of the valueM
- the type of the resulting Map
mapSupplier
- a function which returns a new, empty Map
into
which the results will be insertedCollector
which collects Map.Entry
elements into a
Map
created by mapSupplier
public static <T,K,U> Collector<T,?,Map<K,U>> toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)
Collector
that accumulates elements into a Map
whose keys and values are the result of applying the provided mapping
functions to the input elements.
If the mapped keys contains duplicates (according to
Object.equals(Object)
), an IllegalStateException
is thrown
when the collection operation is performed. If the mapped keys may have
duplicates, use toMap(Function, Function, BinaryOperator)
instead.
T
- the type of the input elementsK
- the output type of the key mapping functionU
- the output type of the value mapping functionkeyMapper
- a mapping function to produce keysvalueMapper
- a mapping function to produce valuesCollector
which collects elements into a Map
whose
keys and values are the result of applying mapping functions to the
input elementspublic static <T,K,U> Collector<T,?,Map<K,U>> toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction)
Collector
that accumulates elements into a Map
whose keys and values are the result of applying the provided mapping
functions to the input elements.
If the mapped keys contains duplicates (according to
Object.equals(Object)
), the value mapping function is applied to each
equal element, and the results are merged using the provided merging
function.
T
- the type of the input elementsK
- the output type of the key mapping functionU
- the output type of the value mapping functionkeyMapper
- a mapping function to produce keysvalueMapper
- a mapping function to produce valuesmergeFunction
- a merge function, used to resolve collisions between
values associated with the same key, as supplied to
Map.merge(Object, Object, java.util.function.BiFunction)
Collector
which collects elements into a Map
whose
keys are the result of applying a key mapping function to the input
elements, and whose values are the result of applying a value mapping
function to all input elements equal to the key and combining them
using the merge functionpublic static <T,K,U,M extends Map<K,U>> Collector<T,?,M> toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, Supplier<M> mapSupplier)
Collector
that accumulates elements into a Map
whose keys and values are the result of applying the provided mapping
functions to the input elements.
If the mapped keys contains duplicates (according to
Object.equals(Object)
), an IllegalStateException
is thrown
when the collection operation is performed. If the mapped keys may have
duplicates, use toMap(Function, Function, BinaryOperator)
instead.
T
- the type of the input elementsK
- the output type of the key mapping functionU
- the output type of the value mapping functionM
- the type of the resulting Map
keyMapper
- a mapping function to produce keysvalueMapper
- a mapping function to produce valuesmapSupplier
- a function which returns a new, empty Map
into
which the results will be insertedCollector
which collects elements into a Map
whose
keys are the result of applying a key mapping function to the input
elements, and whose values are the result of applying a value mapping
function to all input elements equal to the key and combining them
using the merge functionpublic static <T,K,U,M extends Map<K,U>> Collector<T,?,M> toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction, Supplier<M> mapSupplier)
Collector
that accumulates elements into a Map
whose keys and values are the result of applying the provided mapping
functions to the input elements.
If the mapped keys contains duplicates (according to
Object.equals(Object)
), the value mapping function is applied to each
equal element, and the results are merged using the provided merging
function. The Map
is created by a provided supplier function.
T
- the type of the input elementsK
- the output type of the key mapping functionU
- the output type of the value mapping functionM
- the type of the resulting Map
keyMapper
- a mapping function to produce keysvalueMapper
- a mapping function to produce valuesmergeFunction
- a merge function, used to resolve collisions between
values associated with the same key, as supplied to
Map.merge(Object, Object, java.util.function.BiFunction)
mapSupplier
- a function which returns a new, empty Map
into
which the results will be insertedCollector
which collects elements into a Map
whose
keys are the result of applying a key mapping function to the input
elements, and whose values are the result of applying a value mapping
function to all input elements equal to the key and combining them
using the merge functionCopyright © 2025. All rights reserved.