LangCollectors¶
- public final class org.apache.commons.lang3.stream.LangCollectors[source]¶
Implementations of
Collectorthat implement various reduction operations.This class is called
LangCollectorsinstead ofCollectorsto avoid clashes withCollectors.- Since:
3.13.0
Methods¶
Delegates to |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
- @SafeVarargs public static <T, R, A> R collect(Collector<? super T, A, R> collector, T... array)[source]¶
Delegates to
Stream#collect(Collector)for a Stream on the given array.- Type parameters:
<T> – The type of the array elements.
<R> – the type of the result.
<A> – the intermediate accumulation type of the
Collector.
- Parameters:
collector – The
Collectordescribing the reduction.array – The array, assumed to be unmodified during use, a null array treated as an empty array.
- Returns:
The result of the reduction
- See also:
- Since:
3.16.0
- public static Collector<Object, ?, String> joining()[source]¶
Returns a
Collectorthat 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 justCharSequence.For example:
Stream.of(Long.valueOf(1), Long.valueOf(2), Long.valueOf(3)) .collect(LangCollectors.joining()) returns "123"
- Returns:
A
Collectorwhich concatenates Object elements, separated by the specified delimiter, in encounter order.
- public static Collector<Object, ?, String> joining(CharSequence delimiter)[source]¶
Returns a
Collectorthat 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 justCharSequence.For example:
Stream.of(Long.valueOf(1), Long.valueOf(2), Long.valueOf(3)) .collect(LangCollectors.joining("-")) returns "1-2-3"
- Parameters:
delimiter – The delimiter to be used between each element.
- Returns:
A
Collectorwhich concatenates Object elements, separated by the specified delimiter, in encounter order.
- public static Collector<Object, ?, String> joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)[source]¶
Returns a
Collectorthat 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 justCharSequence.For example:
Stream.of(Long.valueOf(1), Long.valueOf(2), Long.valueOf(3)) .collect(LangCollectors.joining("-", "[", "]")) returns "[1-2-3]"
- Parameters:
delimiter – The delimiter to be used between each element
prefix – The sequence of characters to be used at the beginning of the joined result
suffix – The sequence of characters to be used at the end of the joined result
- Returns:
A
Collectorwhich concatenates CharSequence elements, separated by the specified delimiter, in encounter order
- public static Collector<Object, ?, String> joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix, Function<Object, String> toString)[source]¶
Returns a
Collectorthat 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 justCharSequence.For example:
Stream.of(Long.valueOf(1), null, Long.valueOf(3)) .collect(LangCollectors.joining("-", "[", "]", o -> Objects.toString(o, "NUL"))) returns "[1-NUL-3]"
- Parameters:
delimiter – The delimiter to be used between each element
prefix – The sequence of characters to be used at the beginning of the joined result
suffix – The sequence of characters to be used at the end of the joined result
toString – A function that takes an Object and returns a non-null String.
- Returns:
A
Collectorwhich concatenates CharSequence elements, separated by the specified delimiter, in encounter order