public final class StringStreamExtensions extends Object
Stream<String>
and in some cases for
Stream<? extends CharSequence>
.Modifier and Type | Method and Description |
---|---|
static Stream<String> |
flatMatches(Stream<String> stream,
Pattern pattern)
Takes
stream , finds matches in each element of the stream according to
the given pattern and provides all matches in a single stream returned
as the result. |
static Stream<String> |
flatMatches(Stream<String> stream,
String pattern)
Takes
stream , finds matches in each element of the stream according to
the given pattern and provides all matches in a single stream returned
as the result.This method is a wrapper around flatMatches(Stream, Pattern)
first compiling the parameter pattern to a Pattern object then delegating to the wrapped function. |
static Stream<String> |
flatSplit(Stream<? extends CharSequence> stream,
Pattern pattern)
Splitting the elements of the given
stream by the given pattern and returning
a single stream of all results of the splits. |
static Stream<String> |
flatSplit(Stream<? extends CharSequence> stream,
Pattern pattern,
int limit)
Splitting the elements of the given
stream by the given pattern and returning
a single stream of all results of the splits. |
static Stream<String> |
flatSplit(Stream<? extends CharSequence> stream,
String pattern)
Splitting the elements of the given
stream by the given pattern and returning
a single stream of all results of the splits. |
static Stream<String> |
flatSplit(Stream<? extends CharSequence> stream,
String pattern,
int limit)
Splitting the elements of the given
stream by the given pattern and returning
a single stream of all results of the splits. |
static String |
join(Stream<? extends CharSequence> stream)
Shortcut for
stream.collect(Collectors.joining()) . |
static String |
join(Stream<? extends CharSequence> stream,
CharSequence delimiter)
Shortcut for
stream.collect(Collectors.joining(delimiter)) . |
static String |
join(Stream<? extends CharSequence> stream,
CharSequence delimiter,
CharSequence prefix,
CharSequence suffix)
Shortcut for
stream.collect(Collectors.joining(delimiter,prefix)) . |
static <S extends CharSequence> |
matching(Stream<S> stream,
Pattern pattern)
Filtering the given
stream by elements matching the given pattern . |
static <S extends CharSequence> |
matching(Stream<S> stream,
String pattern)
Filtering the given
stream by elements matching the given pattern .This method is a wrapper calling matching(Stream, Pattern)
by compiling the given String pattern to a Pattern object before the call. |
public static String join(Stream<? extends CharSequence> stream)
stream.collect(Collectors.joining())
.stream
- the stream of character sequences to concatenate.stream
Collectors.joining()
public static String join(Stream<? extends CharSequence> stream, CharSequence delimiter)
stream.collect(Collectors.joining(delimiter))
.stream
- the stream of character sequences to concatenate.delimiter
- will be used in between each element in stream
stream
with delimiter
as separator between elements.Collectors.joining(CharSequence)
public static String join(Stream<? extends CharSequence> stream, CharSequence delimiter, CharSequence prefix, CharSequence suffix)
stream.collect(Collectors.joining(delimiter,prefix))
.stream
- the stream of character sequences to concatenate.delimiter
- will be used in between each element in stream
prefix
- will be prepended to the concatenated elements of stream
.suffix
- fill be postpended after the concatenated elements of stream
.stream
Collectors.joining(CharSequence,CharSequence,CharSequence)
public static <S extends CharSequence> Stream<S> matching(Stream<S> stream, String pattern)
stream
by elements matching the given pattern
.matching(Stream, Pattern)
by compiling the given String pattern
to a Pattern
object before the call.S
- Type extending CharSequence
elements in stream
are instance ofstream
- stream to be filtered to only contain elements matching the given pattern
pattern
- the regex pattern to filter element in stream
by.stream
filtered by the given pattern
.public static <S extends CharSequence> Stream<S> matching(Stream<S> stream, Pattern pattern)
stream
by elements matching the given pattern
.S
- Type extending CharSequence
elements in stream
are instance ofstream
- stream to be filtered to only contain elements matching the given pattern
pattern
- the regex pattern to filter element in stream
by.stream
filtered by the given pattern
.public static Stream<String> flatSplit(Stream<? extends CharSequence> stream, String pattern)
stream
by the given pattern
and returning
a single stream of all results of the splits. This can e.g. be useful to split the content
of a file into words:
Files.lines(Paths.get("text.txt"))
.flatSplit("\\s+")
This method is a wrapper around flatSplit(Stream, Pattern)
first compiling the parameter pattern
to a Pattern
object then delegating to the wrapped function.stream
- the stream to be split elements using pattern
pattern
- the pattern used to split elements in stream
stream
using pattern
public static Stream<String> flatSplit(Stream<? extends CharSequence> stream, Pattern pattern)
stream
by the given pattern
and returning
a single stream of all results of the splits. Note that the result will. This can e.g. be useful to split the content
of a file into words:
Files.lines(Paths.get("text.txt"))
.flatSplit("\\s+")
stream
- the stream to be split elements using pattern
pattern
- the pattern used to split elements in stream
stream
using pattern
public static Stream<String> flatSplit(Stream<? extends CharSequence> stream, String pattern, int limit)
stream
by the given pattern
and returning
a single stream of all results of the splits. The maximum number of elements produced by a split
can be set via the limit
parameter. It follows the semantics of the String.split(String,int)
method, so negative values will result in no limit in split elements and a value of 0
leads
to an unlimited amount of split elements, but will drop trailing empty strings.flatSplit(Stream, Pattern, int)
first compiling the parameter pattern
to a Pattern
object then delegating to the wrapped function.stream
- the stream to be split elements using pattern
pattern
- the pattern used to split elements in stream
limit
- limits the amount of elements in which stream
elements are split into, according
to the rules abovestream
using pattern
public static Stream<String> flatSplit(Stream<? extends CharSequence> stream, Pattern pattern, int limit)
stream
by the given pattern
and returning
a single stream of all results of the splits. The maximum number of elements produced by a split
can be set via the limit
parameter. It follows the semantics of the String.split(String,int)
method, so negative values will result in no limit in split elements and a value of 0
leads
to an unlimited amount of split elements, but will drop trailing empty strings.stream
- the stream to be split elements using pattern
pattern
- the pattern used to split elements in stream
limit
- limits the amount of elements in which stream
elements are split into, according
to the rules abovestream
using pattern
public static Stream<String> flatMatches(Stream<String> stream, Pattern pattern)
stream
, finds matches in each element of the stream according to
the given pattern
and provides all matches in a single stream returned
as the result.stream
- elements which are searched for matches according to pattern
pattern
- to find matches in elements of stream
stream
according to pattern
public static Stream<String> flatMatches(Stream<String> stream, String pattern)
stream
, finds matches in each element of the stream according to
the given pattern
and provides all matches in a single stream returned
as the result.flatMatches(Stream, Pattern)
first compiling the parameter pattern
to a Pattern
object then delegating to the wrapped function.stream
- elements which are searched for matches according to pattern
pattern
- to find matches in elements of stream
stream
according to pattern
Copyright © 2019. All rights reserved.