
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 toString Method in Java 8
The toString() method of the StringJoiner class in Java8 is used to return the string representation of the StringJoiner.
The syntax of the toString() method is as follows:
String toString()
To work with the StringJoiner in Java 8, import the following package:
import java.util.StringJoiner;
The following is an example to implement StringJoiner toString() method in Java:
Example
import java.util.StringJoiner; public class Demo { public static void main(String[] args) { StringJoiner strJoin = new StringJoiner(" "); strJoin.add("One"); strJoin.add("Two"); strJoin.add("Three"); strJoin.add("Four"); strJoin.add("Five"); System.out.println(strJoin.toString()); } }
output
One Two Three Four Five
Above, we have set the delimiter as a whitespace:
StringJoiner strJoin = new StringJoiner(" ");
Advertisements