- 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
Collectors.joining() method in Java 8
The joining() method of the Collectors class in Java 8 returns a Collector that concatenates the input elements into a String, in encounter order.
The syntax is as follows −
public static Collector<CharSequence,?,String> joining()
Here, CharSequence is a readable sequence of char values, whereas String class represents character strings.
To work with Collectors class in Java, import the following package −
import java.util.stream.Collectors;
The following is an example to implement Collectors.joining() method in Java 8 −
Example
import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.Arrays; import java.util.List; public class Demo { public static void main(String[] args) { List<Character> list = Arrays.asList('D', 'e', 'm', 'o'); String str = list.stream().map(String::valueOf).collect(Collectors.joining()); System.out.println("Concatenated = "+str); } }
Output
Concatenated = Demo
- Related Articles
- 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
- Collectors collectingAndThen() method in Java 8
- Collectors partitioningBy() method in Java 8
- Collectors toList() method in Java 8\n
- Java Stream Collectors toCollection() in Java
- How to create IntSummaryStatistics from Collectors in Java?
- StringJoiner add() method in Java 8
- StringJoiner setEmptyValue() method in Java 8

Advertisements