public final class LangCollectors extends Object
Collector that implement various reduction operations.
This class is called LangCollectors instead of Collectors to avoid clashes with Collectors.
| Modifier and Type | Method and Description |
|---|---|
static <T,R,A> R |
collect(Collector<? super T,A,R> collector,
T... array)
Delegates to
Stream.collect(Collector) for a Stream on the given array. |
static Collector<Object,?,String> |
joining()
Returns a
Collector that concatenates the input elements, separated by the specified delimiter, in encounter order. |
static Collector<Object,?,String> |
joining(CharSequence delimiter)
Returns a
Collector that concatenates the input elements, separated by the specified delimiter, in encounter order. |
static Collector<Object,?,String> |
joining(CharSequence delimiter,
CharSequence prefix,
CharSequence suffix)
Returns a
Collector that concatenates the input elements, separated by the specified delimiter, with the
specified prefix and suffix, in encounter order. |
static Collector<Object,?,String> |
joining(CharSequence delimiter,
CharSequence prefix,
CharSequence suffix,
Function<Object,String> toString)
Returns a
Collector that concatenates the input elements, separated by the specified delimiter, with the specified prefix and suffix, in
encounter order. |
@SafeVarargs public static <T,R,A> R collect(Collector<? super T,A,R> collector, T... array)
Stream.collect(Collector) for a Stream on the given array.T - The type of the array elements.R - the type of the result.A - the intermediate accumulation type of the Collector.collector - the Collector describing the reduction.array - The array, assumed to be unmodified during use, a null array treated as an empty array.Stream.collect(Collector),
Arrays.stream(Object[]),
Collectorspublic static Collector<Object,?,String> joining()
Collector that concatenates the input elements, separated by the specified delimiter, in encounter order.
This is a variation of Collectors.joining() that works with any element class, not just CharSequence.
For example:
Stream.of(Long.valueOf(1), Long.valueOf(2), Long.valueOf(3))
.collect(LangCollectors.joining())
returns "123"
Collector which concatenates Object elements, separated by the specified delimiter, in encounter order.public static Collector<Object,?,String> joining(CharSequence delimiter)
Collector that concatenates the input elements, separated by the specified delimiter, in encounter order.
This is a variation of Collectors.joining(CharSequence) that works with any element class, not just CharSequence.
For example:
Stream.of(Long.valueOf(1), Long.valueOf(2), Long.valueOf(3))
.collect(LangCollectors.joining("-"))
returns "1-2-3"
delimiter - the delimiter to be used between each element.Collector which concatenates Object elements, separated by the specified delimiter, in encounter order.public static Collector<Object,?,String> joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
Collector that concatenates the input elements, separated by the specified delimiter, with the
specified prefix and suffix, in encounter order.
This is a variation of Collectors.joining(CharSequence, CharSequence, CharSequence) that works with any
element class, not just CharSequence.
For example:
Stream.of(Long.valueOf(1), Long.valueOf(2), Long.valueOf(3))
.collect(LangCollectors.joining("-", "[", "]"))
returns "[1-2-3]"
delimiter - the delimiter to be used between each elementprefix - the sequence of characters to be used at the beginning of the joined resultsuffix - the sequence of characters to be used at the end of the joined resultCollector which concatenates CharSequence elements, separated by the specified delimiter, in
encounter orderpublic static Collector<Object,?,String> joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix, Function<Object,String> toString)
Collector that concatenates the input elements, separated by the specified delimiter, with the specified prefix and suffix, in
encounter order.
This is a variation of Collectors.joining(CharSequence, CharSequence, CharSequence) that works with any element class, not just
CharSequence.
For example:
Stream.of(Long.valueOf(1), null, Long.valueOf(3))
.collect(LangCollectors.joining("-", "[", "]", o -> Objects.toString(o, "NUL")))
returns "[1-NUL-3]"
delimiter - the delimiter to be used between each elementprefix - the sequence of characters to be used at the beginning of the joined resultsuffix - the sequence of characters to be used at the end of the joined resulttoString - A function that takes an Object and returns a non-null String.Collector which concatenates CharSequence elements, separated by the specified delimiter, in encounter orderCopyright © 2001–2025 The Apache Software Foundation. All rights reserved.