Collectors joining(CharSequence delimiter)
returns a Collector that concatenates the input elements, separated by the specified delimiter, in encounter order.
joining
has the following syntax.
public static Collector<CharSequence,?,String> joining(CharSequence delimiter)
The following example shows how to use joining
.
import java.util.stream.Collectors; import java.util.stream.Stream; // w w w.ja va 2 s . c o m 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.