I have a self-made class BitVector with a single field
private boolean[] bits; There is in the same class a small method that makes a conjunction (logical "and") for vectors:
public BitVector and(BitVector anotherVector) { if (this == anotherVector) return (BitVector) clone(); if (size() != anotherVector.size()) throw new IllegalArgumentException("Incompatible sizes: size="+size()+", other.size()="+anotherVector.size()); BitVector intersectionVector = new BitVector(size()); for (int i = 0; i < size(); i++){ if (get(i) & anotherVector.get(i)) intersectionVector.set(i); } return intersectionVector; } public Object clone() { BitVector clone = null; try { clone = (BitVector) super.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } if (this.bits != null) clone.bits = this.bits.clone(); return clone; } public void set(int index){ bits[index] = true; } public boolean get(int index){ return bits[index]; } public int size() { return this.bits.length; } Is it possible to parallelize a single loop within this method using streams? Approximate sizes for the bits field - 1 million