Java Utility Library

Java BitSet - valueOf() Method



The java.util.BitSet.valueOf() method returns a new bit set containing all the bits in the given long array.

More precisely,

BitSet.valueOf(longs).get(n) == ((longs[n/64] & (1<<(n%64))) != 0)
for all n < 64 * longs.length

Syntax

public static BitSet valueOf(long[] longs)

Parameters

longs Specify a long array containing sequence of bits to be used as the initial bits of the new bit set.

Return Value

Returns a BitSet containing all the bits in the long array.

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 array.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a long array
    long Arr[] = {10, 5, 25};

    //creating bit set from given long array
    BitSet BSet = new BitSet();
    BSet = BitSet.valueOf(Arr);

    //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