

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to convert string Stream to join them in Java?
Let us create string Stream:
Stream<String> stream = Stream.of("Bing Bang Theory", "Vampire Diaries", "Game of Thrones", "Homecoming");
Convert the above string stream and join them with Collectors:
final String str = stream.collect(Collectors.joining(" "));
The following is an example to convert string Stream to join them:
Example
import java.util.stream.Collectors; import java.util.stream.Stream; public class Demo { public static void main(String[] args) { Stream<String> stream = Stream.of("Bing Bang Theory", "Vampire Diaries", "Game of Thrones", "Homecoming"); final String str = stream.collect(Collectors.joining(" ")); System.out.println("Join result...\n"+str); } }
Output
Join result... Bing Bang Theory Vampire Diaries Game of Thrones Homecoming
- Related Questions & Answers
- How to convert Stream to TreeSet in Java?
- Convert Stream to Set in Java
- How to convert/read an input stream into a string in java?
- Java Program to convert Stream to List
- Convert an Iterable to Stream in Java
- Convert an Iterator to Stream in Java
- Program to convert List to Stream in Java
- How to convert File into a Stream in Java?
- Java Program to convert Stream to typed array
- How to Convert a Java 8 Stream to an Array?
- Program to convert Primitive Array to Stream in Java
- Program to convert Stream to an Array in Java
- Program to convert Boxed Array to Stream in Java
- How to convert an input stream to byte array in java?
- How to approach String as int stream in Java
Advertisements