Java StringJoiner Class
Java.util package provides a StringJoiner class which 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.
The declaration of java.util.StringJoiner class is:
public final class StringJoiner extends Object
|S.N||Constructors & Description|
Constructs a StringJoiner with no characters in it, with no prefix or suffix, and a copy of the supplied delimiter.
StringJoiner(CharSequence delimiter, CharSequence prefix, CharSequence suffix)|
Constructs a StringJoiner with no characters in it using copies of the supplied prefix, delimiter and suffix.
The java.util.StringJoiner class has a number of methods which are listed below:
|S.N||Methods & Description|
StringJoiner add(CharSequence newElement)|
Adds a copy of the given CharSequence value as the next element of the StringJoiner value.
Returns the length of the String representation of this StringJoiner.
StringJoiner merge(StringJoiner other)|
Adds the contents of the given StringJoiner without prefix and suffix as the next element if it is non-empty.
StringJoiner setEmptyValue(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.
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.
This class inherits the methods of following class: