I have

List<Double> arg = new ArrayList<>(); 

consisting of N elements, is it possible to obtain the product of these N elements without using for loop .

On account of the amount figured out:

 arg1.stream().mapToDouble(dbl -> dbl).sum() 

but with the product is not glued.

    1 answer 1

    There is a great option to use the reduce() function reduce() . Here is an example of using the multiplication of all elements in an ArrayList :

     List<Double> arg = new ArrayList<>(); arg.add(4.0); arg.add(5.0); arg.add(0.0); double mult = arg.stream() .mapToDouble(a -> a) .reduce(1, (a, b) -> a * b); System.out.println(mult); 

    You can check the performance of this program here: https://rextester.com/LZM95702