DoubleStream collect(Supplier supplier, ObjDoubleConsumer accumulator, BiConsumer combiner) example

Description

DoubleStream collect(Supplier<R> supplier, ObjDoubleConsumer<R> accumulator, BiConsumer<R,R> combiner) performs a mutable reduction operation on the elements of this stream.

Syntax

collect has the following syntax.


<R> R collect(Supplier<R> supplier,  ObjDoubleConsumer<R> accumulator,  BiConsumer<R,R> combiner)

Example

The following example shows how to use collect.


import java.util.ArrayList;
import java.util.List;
import java.util.stream.DoubleStream;
/*w w  w  . ja v a  2  s.  c om*/
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.





















Home »
  Java Streams »
    Reference »




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