Java Utility Library

Java.util.StringJoiner Class



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.

Class declaration

The declaration of java.util.StringJoiner class is:

public final class StringJoiner
  extends Object

Class Constructors

S.NConstructors & Description
1. StringJoiner(CharSequence delimiter)
Constructs a StringJoiner with no characters in it, with no prefix or suffix, and a copy of the supplied delimiter.
2. StringJoiner(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
Constructs a StringJoiner with no characters in it using copies of the supplied prefix, delimiter and suffix.

java.util.StringJoiner Methods

The java.util.StringJoiner class has a number of methods which are listed below:

Member Methods

S.NMethods & Description
1. StringJoiner add(CharSequence newElement)
Adds a copy of the given CharSequence value as the next element of the StringJoiner value.
2. int length()
Returns the length of the String representation of this StringJoiner.
3. StringJoiner merge(StringJoiner other)
Adds the contents of the given StringJoiner without prefix and suffix as the next element if it is non-empty.
4. 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.
5. 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.

Methods inherited

This class inherits the methods of following class:

  • java.lang.Object

5