BitSet intersects(BitSet) in Java

intersects(BitSet): This method is available in java.util.BitSet class of Java.

Syntax:

boolean java.util.BitSet.intersects(BitSet set)

This method takes one argument of the type BitSet as its parameter. This method returns true if the specified BitSet has any bits set to true that are also set to true in this BitSet.

Parameters: One parameter is required for this method.

set: BitSet to intersect with.

Returns: boolean indicating whether this BitSet intersects the specified BitSet.

Exceptions: NA

Approach

Java

import java.util.BitSet;

public class BitSetintersects {
    public static void main(String[] args) {
        BitSet bitSet = new BitSet(40);

        bitSet.set(1);

        bitSet.set(5);
        bitSet.set(6);
        bitSet.set(10);
        BitSet bitSet2 = new BitSet(40);

        bitSet2.set(5);
        bitSet2.set(6);
        bitSet2.set(10);
        bitSet2.set(1);

        System.out.println(bitSet.intersects(bitSet2));
    }
}

Output:

true


No comments:

Post a Comment