intersects()
is an instance method of the BitSet
. It checks whether the BitSet
object contains any set bits at the same indices as the specified BitSet
object.
The BitSet
class implements a vector of bits that expands automatically as additional bits are required.
The intersects()
method is defined in the BitSet
class. The BitSet
class is defined in the java.util
package. To import the BitSet
class, check the following import statement:
import java.util.BitSet;
public boolean intersects(BitSet set)
BitSet set
: The BitSet
to intersect with.boolean
: This method returns true
if there are set bits at common indices. Otherwise, it returns false
.import java.util.BitSet;public class Main{public static void main(String[] args) {// Create empty BitSet objectBitSet bitSet1 = new BitSet();// Set the bit at index 2bitSet1.set(2);// Set the bit at index 3bitSet1.set(3);// Create empty BitSet objectBitSet bitSet2 = new BitSet();// Set the bit at index 3bitSet2.set(3);// Set the bit at index 4bitSet2.set(4);// intersects operation on bitset1 and bitset2boolean commonSetBitsFound = bitSet1.intersects(bitSet2);// print the result of the operationSystem.out.printf("%s.intersects(%s) = %s", bitSet1, bitSet2, commonSetBitsFound);}}
BitSet
class.BitSet
object called bitSet1
.2
of the bitSet1
object.3
of the bitSet1
object.BitSet
object called bitSet2
.3
of the bitSet2
object.4
of the bitSet2
object.intersects
operation on bitset1
and bitset2
that returns a boolean
value.intersects
operation.