Java BitSet or() method

The or(BitSet set) method of Java BitSet class is used to perform a logical OR operation of this bit set with the specified set argument. The value of bit set is modified so that each bit in it has true if and only if the bit set of either initially or the corresponding bit argument has the true value.

Syntax:

Parameter:

DataTypeParameterDescription
BitSetsetIt is a bit set.

Returns:

NA

Exception:

NullPointerException - if null parameter will pass in the method.

Compatibility Version:

Java 1.0 and above

Example 1

Output:

bitset1: {0, 1, 4, 6, 7}
bitset2: {2, 4, 6, 8, 10}
or operation between bitsets: {0, 1, 2, 4, 6, 7, 8, 10}

Example 2

The BitSet class converts the character into a byte value.

Output:

bitset1: {4, 5, 97, 98, 99}
bitset2: {3, 4, 6, 97, 98}
or operation between bitsets: {3, 4, 5, 6, 97, 98, 99}

Example 3

This method throws a NullPointerException if we pass a null parameter.

Output:

Exception in thread "main" java.lang.NullPointerException
	at java.util.BitSet.or(Unknown Source)
	at BitSetOrExample3.main(BitSetOrExample3.java:12)