JavaStreamcollect

Performs a mutable reduction using a Collector.

Syntax

stream.collect(collector)

Example

Enter values below to update the example in real time.

List
String
fruits
of
result
stream
collect
Collectors
joining
System
out
println
List<String> fruits = List.of("apple", "banana", "cherry");
String result = fruits.stream()
    .collect(Collectors.joining(", "));
System.out.println(result); // "apple, banana, cherry"