Java BitSet - valueOf() Method
The java.util.BitSet.valueOf() method returns a new bit set containing all the bits in the given long buffer between its position and limit.
More precisely,
BitSet.valueOf(lb).get(n) == ((lb.get(lb.position()+n/64) & (1<<(n%64))) != 0) for all n < 64 * lb.remaining()
Syntax
public static BitSet valueOf(LongBuffer lb)
Parameters
lb |
Specify a long buffer containing a sequence of bits between its position and limit, to be used as the initial bits of the new bit set. |
Return Value
Returns a BitSet containing all the bits in the buffer in the specified range.
Exception
NA.
Example:
In the example below, the java.util.BitSet.valueOf() method returns a BitSet which contains all the bits in the specified long buffer.
import java.util.*; import java.nio.LongBuffer; public class MyClass { public static void main(String[] args) { //creating a long buffer LongBuffer lb = LongBuffer.wrap(new long[]{10, 5, 25}); //creating bit set from given long buffer BitSet BSet = new BitSet(); BSet = BitSet.valueOf(lb); //printing BitSet System.out.println("BSet contains: " + BSet); } }
The output of the above code will be:
BSet contains: {1, 3, 64, 66, 128, 131, 132}
❮ Java.util - BitSet