DoubleStream flatMapToDouble(Function<? super T,? extends DoubleStream> mapper)
This intermediate operation returns an DoubleStream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.
DoubleStream dStream = listOfLists.stream().flatMapToDouble(childList -> childList.stream() .mapToDouble(Double::new)); //let's peek and find average of the elements OptionalDouble opt = dStream.peek(System.out::println) .average(); if (opt.isPresent()) { System.out.println("average: " + opt.getAsDouble()); } } }