Java Stream – ParallelStream

Multiple All BigInteger in Array using Parallel Stream and reduce

package com.dw.thread;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

public class ParallelStreamTest {
    public static void main(String[] args) {
        List<BigInteger> integers = new ArrayList<>();
// fill data
        integers.add(new BigInteger("134123124325234234"));
        integers.add(new BigInteger("1341231243252"));
        integers.add(new BigInteger("134123124325234234"));
        integers.add(new BigInteger("134123124325234234"));
        integers.add(new BigInteger("134123124"));
        integers.add(new BigInteger("134123124"));
        integers.add(new BigInteger("134123124"));
        integers.add(new BigInteger("134123124"));
        integers.add(new BigInteger("134123124"));

        BigInteger result = integers.parallelStream()
                .reduce(BigInteger.ONE, (a, e) -> a.multiply(e));
        System.out.println(result);

    }
}