Choose the correct option based on this program:.
import java.util.stream.DoubleStream; public class Main { public static void main(String []args) { DoubleStream nums = DoubleStream.of (1.0, 2.0, 3.0).map(i -> -i); // #1 System.out .printf("count = %d, sum = %f", nums.count(), nums.sum()); } }
d.
a stream is considered "consumed" when a terminal operation is called on that stream.
the methods count()
and sum()
are terminal operations in DoubleStream.
When this code calls nums
.count()
, the underlying stream is already "consumed".
When the printf calls nums.sum()
, this program results in throwing java.lang.IllegalStateException due to the attempt to use a consumed stream.