I'm trying to develop an efficient method to perform logical AND operation among several BigInteger values. For example, let us consider the snippet below:
public static void main(String[] args) {
List<BigInteger> a = Arrays.asList(new BigInteger("1000",2), new BigInteger("101",2), new BigInteger("111",2));
List<BigInteger> b = Arrays.asList(new BigInteger("10",2), new BigInteger("10110",2), new BigInteger("10011",2));
List<BigInteger> c = Arrays.asList(new BigInteger("1",2), new BigInteger("10110",2), new BigInteger("11110",2));
List<BigInteger> dd = IntStream.range(0, a.size())
.mapToObj(i -> a.get(i).and(b.get(i)).and(c.get(i)))
.collect(Collectors.toList());
System.out.println(dd);
//OUTPUT = [0, 4, 2]
}
However, the problem of this solution is the static number of values accepted by the map function. Let us suppose to consider an ArrayList containing several lists (also more than 3), how can I change the previous solution?
public static void main(String[] args) {
List<BigInteger> a = Arrays.asList(new BigInteger("1000",2), new BigInteger("101",2), new BigInteger("111",2));
List<BigInteger> b = Arrays.asList(new BigInteger("10",2), new BigInteger("10110",2), new BigInteger("10011",2));
List<BigInteger> c = Arrays.asList(new BigInteger("1",2), new BigInteger("10110",2), new BigInteger("11110",2));
ArrayList<List<BigInteger>> collection = new ArrayList<List<BigInteger>>();
collection.add(a);
collection.add(b);
collection.add(c);
List<BigInteger> dd = null;
//......
System.out.println(dd);
}
Notice that, I've decided to choose adopting stream.map() since the number of the BigInteger values in the lists could be large (thousands of values) and I would like to exploit parallelStream() to perform this operation. However, I accept any advice to do this efficiently.