- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
- Related Articles
- StringJoiner add() method in Java 8
- StringJoiner toString() method in Java 8
- StringJoiner merge() method in Java 8
- StringJoiner length() method in Java 8
- What is StringJoiner class in Java 8?
- StringJoiner Class vs String.join() Method to Join String in Java
- Collectors.joining() method in Java 8
- Collectors toSet() method in Java 8
- Collectors averagingLong () method in Java 8
- Collectors averagingDouble() method in Java 8
- Collectors counting() method in Java 8
- Collectors averagingInt() method in Java 8
- Collectors toCollection() method in Java 8
- Collectors maxBy() method in Java 8
- Collectors minBy() method in Java 8

Advertisements