The setEmptyValue(CharSequence emptyValue) of StringJoiner 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. 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.
public StringJoiner setEmptyValue(CharSequence emptyValue)
Parameters: This method accepts a mandatory parameter emptyValue which is the characters to return as the value of an empty StringJoiner
Returns: This method returns this StringJoiner itself, so the calls may be chained
Exception: This method throws NullPointerException when the emptyValue parameter is null
Below examples illustrates the setEmptyValue() method:
Initial StringJoiner: After setEmptyValue(): StrigJoiner is empty Final StringJoiner: Geeks forGeeks
Example 2: To demonstrate NullPointerException
Initial StringJoiner: Exception when adding null in setEmptyValue(): java.lang.NullPointerException: The empty value must not be null
- StringJoiner add() method in Java
- StringJoiner length() method in Java
- StringJoiner merge() method in Java
- StringJoiner toString() method in Java
- Java.util.StringJoiner in Java8
- When to use StringJoiner over StringBuilder?
- Java lang.Long.byteValue() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java.lang.Short toString() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.