Collectors joining() method in Java

In this post, we will talk about Collectors joining() method in Java.

 

1. Collectors.joining()

Collectors.joining() method returns a Collector that concatenates the input elements into a single String.

 

1. Convert a character array to a String

 

Download   Run Code

Output:

Java

 

2. Convert a List of Character to a String

 

Download   Run Code

Output:

Java

 

2. Collectors.joining(delimiter)

Collectors.joining(delimiter) returns a Collector that concatenates the input elements, separated by the specified delimiter.

 

Download   Run Code

Output:

RED, BLUE, BLACK, GREEN

 

3. Collectors.joining(delimiter, prefix, suffix)

Collectors.joining(delimiter, prefix, suffix) returns a Collector that concatenates the input elements, separated by the specified delimiter, with the specified prefix and suffix.

 

Download   Run Code

Output:

{RED, BLUE, BLACK, GREEN}

 

 
Thanks for reading.

Please use ideone or C++ Shell or any other online compiler link to post code in comments.
Like us? Please spread the word and help us grow. Happy coding 🙂
 


Get great deals at Amazon




Leave a Reply

avatar
  Subscribe  
Notify of