public class Joiner
extends java.lang.Object
StringJoiner
is used to construct a sequence of characters separated
by a delimiter and optionally starting with a supplied prefix
and ending with a supplied suffix.
Prior to adding something to the StringJoiner
, its
sj.toString()
method will, by default, return prefix + suffix
.
However, if the setEmptyValue
method is called, the emptyValue
supplied will be returned instead. This can be used, for example, when
creating a string using set notation to indicate an empty set, i.e.
"{}"
, where the prefix
is "{"
, the
suffix
is "}"
and nothing has been added to the
StringJoiner
.
Collectors.joining(CharSequence)
,
Collectors.joining(CharSequence, CharSequence, CharSequence)
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_DELIMITER |
static java.lang.String |
DEFAULT_KEY_VALUE_DELIMITER |
Modifier and Type | Method and Description |
---|---|
Joiner |
add(boolean element) |
Joiner |
add(byte element) |
Joiner |
add(char element) |
Joiner |
add(java.lang.CharSequence element)
Adds a copy of the given
CharSequence value as the next
element of the StringJoiner value. |
Joiner |
add(double element) |
Joiner |
add(float element) |
Joiner |
add(int element) |
Joiner |
add(long element) |
Joiner |
add(java.lang.Object element) |
Joiner |
add(short element) |
Joiner |
add(java.lang.String element) |
static Joiner |
defauLt()
Returns the Map Splitter with the default element and key/value delimiter:
", " and "=" |
Joiner |
join(boolean[] a) |
Joiner |
join(boolean[] a,
int fromIndex,
int toIndex) |
Joiner |
join(BooleanList c) |
Joiner |
join(BooleanList c,
int fromIndex,
int toIndex) |
Joiner |
join(byte[] a) |
Joiner |
join(byte[] a,
int fromIndex,
int toIndex) |
Joiner |
join(ByteList c) |
Joiner |
join(ByteList c,
int fromIndex,
int toIndex) |
Joiner |
join(char[] a) |
Joiner |
join(char[] a,
int fromIndex,
int toIndex) |
Joiner |
join(CharList c) |
Joiner |
join(CharList c,
int fromIndex,
int toIndex) |
Joiner |
join(java.util.Collection<?> c) |
Joiner |
join(java.util.Collection<?> c,
int fromIndex,
int toIndex) |
Joiner |
join(double[] a) |
Joiner |
join(double[] a,
int fromIndex,
int toIndex) |
Joiner |
join(DoubleList c) |
Joiner |
join(DoubleList c,
int fromIndex,
int toIndex) |
Joiner |
join(float[] a) |
Joiner |
join(float[] a,
int fromIndex,
int toIndex) |
Joiner |
join(FloatList c) |
Joiner |
join(FloatList c,
int fromIndex,
int toIndex) |
Joiner |
join(int[] a) |
Joiner |
join(int[] a,
int fromIndex,
int toIndex) |
Joiner |
join(IntList c) |
Joiner |
join(IntList c,
int fromIndex,
int toIndex) |
Joiner |
join(long[] a) |
Joiner |
join(long[] a,
int fromIndex,
int toIndex) |
Joiner |
join(LongList c) |
Joiner |
join(LongList c,
int fromIndex,
int toIndex) |
Joiner |
join(java.util.Map<?,?> m) |
Joiner |
join(java.util.Map<?,?> m,
int fromIndex,
int toIndex) |
Joiner |
join(java.lang.Object[] a) |
Joiner |
join(java.lang.Object[] a,
int fromIndex,
int toIndex) |
Joiner |
join(short[] a) |
Joiner |
join(short[] a,
int fromIndex,
int toIndex) |
Joiner |
join(ShortList c) |
Joiner |
join(ShortList c,
int fromIndex,
int toIndex) |
int |
length()
Returns the length of the
String representation
of this StringJoiner . |
<T> T |
map(Function<? super java.lang.String,T> mapper) |
<T> Optional<T> |
mapIfNotEmpty(Function<? super java.lang.String,T> mapper) |
Joiner |
merge(Joiner other)
Adds the contents of the given
StringJoiner without prefix and
suffix as the next element if it is non-empty. |
Joiner |
setEmptyValue(java.lang.CharSequence emptyValue)
Sets the sequence of characters to be used when determining the string
representation of this
StringJoiner and no elements have been
added yet, that is, when it is empty. |
Joiner |
skipNull(boolean skipNull) |
Stream<java.lang.String> |
stream() |
Stream<java.lang.String> |
streamIfNotEmpty() |
java.lang.String |
toString()
Returns the current value, consisting of the
prefix , the values
added so far separated by the delimiter , and the suffix ,
unless no elements have been added in which case, the
prefix + suffix or the emptyValue characters are returned |
Joiner |
trim(boolean trim) |
Joiner |
useForNull(java.lang.String nullText) |
static Joiner |
with(java.lang.CharSequence delimiter) |
static Joiner |
with(java.lang.CharSequence delimiter,
java.lang.CharSequence keyValueDelimiter) |
static Joiner |
with(java.lang.CharSequence delimiter,
java.lang.CharSequence prefix,
java.lang.CharSequence suffix) |
static Joiner |
with(java.lang.CharSequence delimiter,
java.lang.CharSequence keyValueDelimiter,
java.lang.CharSequence prefix,
java.lang.CharSequence suffix) |
public static final java.lang.String DEFAULT_DELIMITER
public static final java.lang.String DEFAULT_KEY_VALUE_DELIMITER
public static Joiner defauLt()
", "
and "="
public static Joiner with(java.lang.CharSequence delimiter)
public static Joiner with(java.lang.CharSequence delimiter, java.lang.CharSequence keyValueDelimiter)
public static Joiner with(java.lang.CharSequence delimiter, java.lang.CharSequence prefix, java.lang.CharSequence suffix)
public static Joiner with(java.lang.CharSequence delimiter, java.lang.CharSequence keyValueDelimiter, java.lang.CharSequence prefix, java.lang.CharSequence suffix)
public Joiner setEmptyValue(java.lang.CharSequence emptyValue)
StringJoiner
and no elements have been
added yet, that is, when it is empty. A copy of the emptyValue
parameter is made for this purpose. Note that once an add method has been
called, the StringJoiner
is no longer considered empty, even if
the element(s) added correspond to the empty String
.emptyValue
- the characters to return as the value of an empty
StringJoiner
StringJoiner
itself so the calls may be chainedjava.lang.NullPointerException
- when the emptyValue
parameter is
null
public Joiner trim(boolean trim)
public Joiner skipNull(boolean skipNull)
public Joiner useForNull(java.lang.String nullText)
public Joiner add(boolean element)
public Joiner add(char element)
public Joiner add(byte element)
public Joiner add(short element)
public Joiner add(int element)
public Joiner add(long element)
public Joiner add(float element)
public Joiner add(double element)
public Joiner add(java.lang.String element)
public Joiner add(java.lang.CharSequence element)
CharSequence
value as the next
element of the StringJoiner
value. If element
is
null
, then "null"
is added.element
- The element to addStringJoiner
public Joiner add(java.lang.Object element)
public Joiner join(boolean[] a)
public Joiner join(boolean[] a, int fromIndex, int toIndex)
public Joiner join(char[] a)
public Joiner join(char[] a, int fromIndex, int toIndex)
public Joiner join(byte[] a)
public Joiner join(byte[] a, int fromIndex, int toIndex)
public Joiner join(short[] a)
public Joiner join(short[] a, int fromIndex, int toIndex)
public Joiner join(int[] a)
public Joiner join(int[] a, int fromIndex, int toIndex)
public Joiner join(long[] a)
public Joiner join(long[] a, int fromIndex, int toIndex)
public Joiner join(float[] a)
public Joiner join(float[] a, int fromIndex, int toIndex)
public Joiner join(double[] a)
public Joiner join(double[] a, int fromIndex, int toIndex)
public Joiner join(java.lang.Object[] a)
public Joiner join(java.lang.Object[] a, int fromIndex, int toIndex)
public Joiner join(java.util.Collection<?> c)
public Joiner join(java.util.Collection<?> c, int fromIndex, int toIndex)
public Joiner join(java.util.Map<?,?> m)
public Joiner join(java.util.Map<?,?> m, int fromIndex, int toIndex)
public Joiner join(BooleanList c)
public Joiner join(BooleanList c, int fromIndex, int toIndex)
public Joiner join(DoubleList c)
public Joiner join(DoubleList c, int fromIndex, int toIndex)
public Joiner merge(Joiner other)
StringJoiner
without prefix and
suffix as the next element if it is non-empty. If the given StringJoiner
is empty, the call has no effect.
A StringJoiner
is empty if add()
has never been called, and if merge()
has never been called
with a non-empty StringJoiner
argument.
If the other StringJoiner
is using a different delimiter,
then elements from the other StringJoiner
are concatenated with
that delimiter and the result is appended to this StringJoiner
as a single element.
other
- The StringJoiner
whose contents should be merged
into this oneStringJoiner
java.lang.NullPointerException
- if the other StringJoiner
is nullpublic int length()
String
representation
of this StringJoiner
. Note that if
no add methods have been called, then the length of the String
representation (either prefix + suffix
or emptyValue
)
will be returned. The value should be equivalent to
toString().length()
.StringJoiner
public java.lang.String toString()
prefix
, the values
added so far separated by the delimiter
, and the suffix
,
unless no elements have been added in which case, the
prefix + suffix
or the emptyValue
characters are returnedtoString
in class java.lang.Object
StringJoiner
public <T> T map(Function<? super java.lang.String,T> mapper)
public Stream<java.lang.String> stream()
public Stream<java.lang.String> streamIfNotEmpty()