Collectors summingDouble(ToDoubleFunction<? super T> mapper)
returns a Collector that produces the sum of a double-valued function applied to the input elements.
summingDouble
has the following syntax.
public static <T> Collector<T,?,Double> summingDouble(ToDoubleFunction<? super T> mapper)
The following example shows how to use summingDouble
.
import java.util.stream.Collectors; import java.util.stream.Stream; /*from www . ja v a 2s . c o m*/ public class Main { public static void main(String[] args) { Stream<String> s = Stream.of("1","2","3"); double o = s.collect(Collectors.summingDouble(n->Double.parseDouble(n))); System.out.println(o); } }
The code above generates the following result.