Search code examples
javaandroidbiginteger

Multiplying Bigintegers in parallel mode


I want to write an android code which multiplies 10,000 numbers in parallel mode. For example divide them into groups and multiply each group in thread..((async task)) and then multiply the results of each group. But I dont know how to do it, can anyone help?


Solution

  • Use parallel stream.

    List<BigInteger> integers = new ArrayList<>();
    // fill data
    BigInteger result = integers.parallelStream()
        .reduce(BigInteger.ONE, (a, e) -> a.multiply(e));
    System.out.println(result);