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}

 

 
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Loading...

Thanks for reading.

Please use our online compiler to post code in comments. To contribute, get in touch with us.
Like us? Please spread the word and help us grow. Happy coding 🙂
 



Leave a Reply

avatar
  Subscribe  
Notify of