Java BitSet valueOf() method

The valueOf() method of Java BitSet class returns a new bit set which contains all the set bit of given parameter.

Syntax:

Parameter:

DataTypeParameterDescription
bytebytes[]It is a byte array represents a sequence of bits.
longlongs[]It is a long array represents a sequence of bits.
ByteBufferbbIt is a byte buffer represents a sequence of bits.
LongBufferlbIt is a long buffer represents a sequence of bits.

Returns:

MethodReturns
valueOf(byte[] bytes)It returns a new bit set of the given byte array.
valueOf(long[] longs)It returns a new bit set of the given long array.
valueOf(ByteBuffer bb)It returns a new bit set of the given byte buffer.
valueOf(LongBuffer lb)It returns a new bit set of the given long buffer.

Exception:

NullPointerException -If null parameter will pass in the method.

Compatibility Version:

Java 1.7 and above

Example of Java BitSet valueOf(byte[] bytes) method

Example 1

Output:

bitset: {}
bitset valueOf bytes: {0, 8, 9, 18}

Example of Java BitSet valueOf(long[] longs) method

Example 2

Output:

bitset: {}
bitset valueOf long: {0, 64, 65, 130}

Example of Java BitSet valueOf(ByteBuffer bb) method

Example 3

Output:

bitset: {}
bitset valueOf bytebuffer: {0, 8, 9, 18}

Example of Java BitSet valueOf(LongBuffer lb) method

Example 4

Output:

bitset: {}
bitset valueOf longbuffer: {0, 64, 65, 130}