Collectors joining() example

Description

Collectors joining() returns a Collector that concatenates the input elements into a String, in encounter order.

Syntax

joining has the following syntax.


public static Collector<CharSequence,?,String> joining()

Example

The following example shows how to use joining.


import java.util.stream.Collectors;
import java.util.stream.Stream;
//from   w w w  .j  av  a2  s .com
public class Main {
  public static void main(String[] args) {
    Stream<String> s = Stream.of("a","b","c");
    
    String names = s
        .collect(Collectors.joining());

    System.out.println(names);
  }
}

The code above generates the following result.





















Home »
  Java Streams »
    Reference »




Collectors
DoubleStream
DoubleStream.Builder
IntStream
IntStream.Builder
LongStream
LongStream.Builder
Stream
Stream.Builder