
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
StringJoiner setEmptyValue Method in Java 8
The setEmptyValue() method of the StringJoiner class in Java 8 sets the sequence of characters. These characters are to be used when determining the string representation of this StringJoiner and when it is empty. That would be none of the elements have been added.
The syntax is as follows
public StringJoiner setEmptyValue(CharSequence emptyVal)
Here, emptyVal are the characters to return as the value of an empty StringJoiner
To work with the StringJoiner in Java 8, import the following package.
import java.util.StringJoiner;
The following is an example to implement StringJoiner setEmptyValue() method in Java:
Example
import java.util.StringJoiner; public class Demo { public static void main(String[] args) { StringJoiner strJoiner = new StringJoiner(","); System.out.println("StringJoiner is empty" + strJoiner); System.out.println(strJoiner.setEmptyValue("Empty!")); System.out.println(strJoiner); System.out.println("After Adding elements to the StringJoiner..."); strJoiner.add("John"); strJoiner.add("Tim"); strJoiner.add("Jacob"); strJoiner.add("Kevin"); strJoiner.add("David"); strJoiner.add("Tom"); System.out.println(strJoiner); } }
Output
StringJoiner is empty Empty! Empty! After Adding elements to the StringJoiner... John,Tim,Jacob,Kevin,David,Tom
Advertisements