valueOf()
is a static method of the BitSet
class that gets a BitSet
object from any of the following data structures:
LongBuffer
long
arrayByteBuffer
byte
arrayThe valueOf
method is defined in the BitSet
class. The BitSet
class is defined in the java.util
package. To import the BitSet
class check the following import statement:
import java.util.BitSet;
valueOf(long[] longs)
This method creates a BitSet
object from a long
array.
public static BitSet valueOf(long[] longs)
long[] longs
: The array to convert to the BitSet
object.This method returns a BitSet
object.
valueOf(LongBuffer lb)
This method creates a BitSet
object from the LongBuffer
object.
public static BitSet valueOf(LongBuffer lb)
LongBuffer lb
: The buffer to convert to the BitSet
object.This method returns a BitSet
object.
valueOf(byte[] bytes)
This method creates a BitSet
object from a byte array.
public static BitSet valueOf(byte[] bytes)
byte[] bytes
: The byte array to convert to the BitSet
object.This method returns a BitSet
object.
valueOf(ByteBuffer bb)
This method creates a BitSet
object from a byte buffer.
public static BitSet valueOf(ByteBuffer bb)
ByteBuffer bb
: The byte buffer to convert to the BitSet
object.This method returns a BitSet
object.
import java.nio.ByteBuffer;import java.nio.LongBuffer;import java.util.Arrays;import java.util.BitSet;public class Main {private static void bitSetFromLongArray(){long[] longs = {4, 8, 16, 32};BitSet bitSet = BitSet.valueOf(longs);System.out.printf("%s converted to BitSet object - %s\n", Arrays.toString(longs), bitSet);}private static void bitSetFromLongBuffer(){LongBuffer longBuffer = LongBuffer.wrap(new long[] { 5, 3, 2 });BitSet bitSet = BitSet.valueOf(longBuffer);System.out.printf("%s converted to BitSet object - %s\n", longBuffer, bitSet);}private static void bitSetFromByteArray(){byte[] bytes = new byte[]{4, 3, 1};BitSet bitSet = BitSet.valueOf(bytes);System.out.printf("%s converted to BitSet object - %s\n", Arrays.toString(bytes), bitSet);}private static void bitSetFromByteBuffer(){ByteBuffer bb = ByteBuffer.wrap(new byte[] { 5, 3, 2 });BitSet bitSet = BitSet.valueOf(bb);System.out.printf("%s converted to BitSet object - %s\n", bb, bitSet);}public static void main(String[] args) {bitSetFromLongArray();bitSetFromByteArray();bitSetFromByteBuffer();bitSetFromLongBuffer();}}
long
array.valueOf()
method to convert the long
array to the BitSet
object.long
array and the created BitSet
object.LongBuffer
.valueOf()
method to convert the LongBuffer
to the BitSet
object.LongBuffer
and the created BitSet
object.byte
array.valueOf()
method to convert the byte
array to the BitSet
object.byte
array and the created BitSet
object.ByteBuffer
.valueOf()
method to convert the ByteBuffer
to the BitSet
object.ByteBuffer
and the created BitSet
object.