DoubleStream collect(Supplier<R> supplier,
ObjDoubleConsumer<R> accumulator, BiConsumer<R,R> combiner)
performs a mutable reduction operation on the elements of this stream.
collect
has the following syntax.
<R> R collect(Supplier<R> supplier, ObjDoubleConsumer<R> accumulator, BiConsumer<R,R> combiner)
The following example shows how to use collect
.
import java.util.ArrayList; import java.util.List; import java.util.stream.DoubleStream; /* w w w.j av a 2 s . c o m*/ public class Main { public static void main(String[] args) { DoubleStream b = DoubleStream.of(1.1,2.2,3.3,4.4,5.5); List<Double> names = b .collect(ArrayList::new, ArrayList::add, ArrayList::addAll); System.out.println(names); } }
The code above generates the following result.