
- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
Java BitSet valueOf(byte[] bytes) Method
Description
The Java BitSet valueOf(byte[] bytes) method return a new bit set containing all the bits in the given byte array. This method is same as BitSet.valueOf(ByteBuffer.wrap(bytes)).
Declaration
Following is the declaration for java.util.BitSet.valueOf(byte[] bytes) method
public static BitSet valueOf(byte[] bytes)
Parameters
bytes− a byte array containing a little-endian representation of a sequence of bits to be used as the initial bits of the new bit set.
Return Value
This method returns a BitSet containing all the bits in the byte array.
Exception
NA
Java BitSet valueOf(long[]) Method
Description
The Java BitSet valueOf(long[] longs) method return a new bit set containing all the bits in the given long array. This method is same as BitSet.valueOf(LongBuffer.wrap(longs)).
Declaration
Following is the declaration for java.util.BitSet.valueOf(long[] longs) method
public static BitSet valueOf(long[] longs)
Parameters
longs− a long array containing a little-endian representation of a sequence of bits to be used as the initial bits of the new bit set.
Return Value
This method returns a BitSet containing all the bits in the long array.
Exception
NA
Java BitSet valueOf(ByteBuffer) Method
Description
The Java BitSet valueOf(ByteBuffer bb) method return a new bit set containing all the bits in the given bytebuffer. The byte buffer is not modified with the use of this method, and no reference to the buffer is retained by the bit set.
Declaration
Following is the declaration for java.util.BitSet.valueOf(ByteBuffer bb) method
public static BitSet valueOf(ByteBuffer bb)
Parameters
bb− a byte buffer containing a little-endian representation of a sequence of bits between its position and limit, to be used as the initial bits of the new bit set.
Return Value
This method returns a BitSet containing all the bits in the buffer in the specified range.
Exception
NA
Java BitSet valueOf(LongBuffer) Method
Description
The Java BitSet valueOf(LongBuffer lb) method return a new bit set containing all the bits in the given long buffer. The long buffer is not modified with the use of this method, and no reference to the buffer is retained by the bit set.
Declaration
Following is the declaration for java.util.BitSet.valueOf(LongBuffer lb) method
public static BitSet valueOf(LongBuffer lb)
Parameters
lb− a byte buffer containing a little-endian representation of a sequence of bits between its position and limit, to be used as the initial bits of the new bit set.
Return Value
This method returns a BitSet containing all the bits in the buffer in the specified range.
Exception
NA
Creating a BitSet using byte[] Example
The following example shows the usage of Java BitSet valueOf(byte[]) method. We're creating two BitSets using byte[] and printing them.
package com.tutorialspoint; import java.util.BitSet; public class BitSetDemo { public static void main(String[] args) { // create 2 bitsets BitSet bitset1 = BitSet.valueOf(new byte[] { 0, 1, 2, 3, 4, 5 }); BitSet bitset2 = BitSet.valueOf(new byte[] { 2, 4, 6, 8, 10 }); // print the sets System.out.println("Bitset1:" + bitset1); System.out.println("Bitset2:" + bitset2); } }
Output
Let us compile and run the above program, this will produce the following result −
Bitset1:{8, 17, 24, 25, 34, 40, 42} Bitset2:{1, 10, 17, 18, 27, 33, 35}
Creating a BitSet using long[] Example
The following example shows the usage of Java BitSet valueOf(long[]) method. We're creating two BitSets using long[] and then printing the bitsets.
package com.tutorialspoint; import java.util.BitSet; public class BitSetDemo { public static void main(String[] args) { // create 2 bitsets BitSet bitset1 = BitSet.valueOf(new long[] { 0, 1, 2, 3, 4, 5 }); BitSet bitset2 = BitSet.valueOf(new long[] { 2, 4, 6, 8, 10 }); // print the sets System.out.println("Bitset1:" + bitset1); System.out.println("Bitset2:" + bitset2); } }
Output
Let us compile and run the above program, this will produce the following result −
Bitset1:{64, 129, 192, 193, 258, 320, 322} Bitset2:{1, 66, 129, 130, 195, 257, 259}
Creating a BitSet using ByteBuffer Example
The following example shows the usage of Java BitSet valueOf(ByteBuffer) method. We're creating two BitSets using ByteBuffer objects and printing them.
package com.tutorialspoint; import java.nio.ByteBuffer; import java.util.BitSet; public class BitSetDemo { public static void main(String[] args) { // create 2 bitsets BitSet bitset1 = BitSet.valueOf(ByteBuffer.wrap(new byte[] { 0, 1, 2, 3, 4, 5 })); BitSet bitset2 = BitSet.valueOf(ByteBuffer.wrap(new byte[] { 2, 4, 6, 8, 10 })); // print the sets System.out.println("Bitset1:" + bitset1); System.out.println("Bitset2:" + bitset2); } }
Output
Let us compile and run the above program, this will produce the following result −
Bitset1:{8, 17, 24, 25, 34, 40, 42} Bitset2:{1, 10, 17, 18, 27, 33, 35}
Creating a BitSet using LongBuffer Example
The following example shows the usage of Java BitSet valueOf(LongBuffer) method. We're creating two BitSets using LongBuffer objects and printing them.
package com.tutorialspoint; import java.nio.LongBuffer; import java.util.BitSet; public class BitSetDemo { public static void main(String[] args) { // create 2 bitsets BitSet bitset1 = BitSet.valueOf(LongBuffer.wrap(new long[] { 0, 1, 2, 3, 4, 5 })); BitSet bitset2 = BitSet.valueOf(LongBuffer.wrap(new long[] { 2, 4, 6, 8, 10 })); // print the sets System.out.println("Bitset1:" + bitset1); System.out.println("Bitset2:" + bitset2); } }
Output
Let us compile and run the above program, this will produce the following result −
Bitset1:{8, 17, 24, 25, 34, 40, 42} Bitset2:{1, 10, 17, 18, 27, 33, 35}