Package org.apache.commons.lang3.stream
Class LangCollectors
- java.lang.Object
-
- org.apache.commons.lang3.stream.LangCollectors
-
public final class LangCollectors extends java.lang.ObjectImplementations ofCollectorthat implement various reduction operations.This class is called
LangCollectorsinstead ofCollectorsto avoid clashes withCollectors.- Since:
- 3.13.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,R,A>
Rcollect(java.util.stream.Collector<? super T,A,R> collector, T... array)Delegates toStream.collect(Collector)for a Stream on the given array.static java.util.stream.Collector<java.lang.Object,?,java.lang.String>joining()Returns aCollectorthat concatenates the input elements, separated by the specified delimiter, in encounter order.static java.util.stream.Collector<java.lang.Object,?,java.lang.String>joining(java.lang.CharSequence delimiter)Returns aCollectorthat concatenates the input elements, separated by the specified delimiter, in encounter order.static java.util.stream.Collector<java.lang.Object,?,java.lang.String>joining(java.lang.CharSequence delimiter, java.lang.CharSequence prefix, java.lang.CharSequence suffix)Returns aCollectorthat concatenates the input elements, separated by the specified delimiter, with the specified prefix and suffix, in encounter order.static java.util.stream.Collector<java.lang.Object,?,java.lang.String>joining(java.lang.CharSequence delimiter, java.lang.CharSequence prefix, java.lang.CharSequence suffix, java.util.function.Function<java.lang.Object,java.lang.String> toString)Returns aCollectorthat concatenates the input elements, separated by the specified delimiter, with the specified prefix and suffix, in encounter order.
-
-
-
Method Detail
-
collect
@SafeVarargs public static <T,R,A> R collect(java.util.stream.Collector<? super T,A,R> collector, T... array)Delegates toStream.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 theCollector.- Parameters:
collector- theCollectordescribing 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
- Since:
- 3.16.0
- See Also:
Stream.collect(Collector),Arrays.stream(Object[]),Collectors
-
joining
public static java.util.stream.Collector<java.lang.Object,?,java.lang.String> joining()
Returns aCollectorthat 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.
-
joining
public static java.util.stream.Collector<java.lang.Object,?,java.lang.String> joining(java.lang.CharSequence delimiter)
Returns aCollectorthat 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.
-
joining
public static java.util.stream.Collector<java.lang.Object,?,java.lang.String> joining(java.lang.CharSequence delimiter, java.lang.CharSequence prefix, java.lang.CharSequence suffix)Returns aCollectorthat 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 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 result- Returns:
- A
Collectorwhich concatenates CharSequence elements, separated by the specified delimiter, in encounter order
-
joining
public static java.util.stream.Collector<java.lang.Object,?,java.lang.String> joining(java.lang.CharSequence delimiter, java.lang.CharSequence prefix, java.lang.CharSequence suffix, java.util.function.Function<java.lang.Object,java.lang.String> toString)Returns aCollectorthat 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 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.- Returns:
- A
Collectorwhich concatenates CharSequence elements, separated by the specified delimiter, in encounter order
-
-