BitSet.valueOf(ByteBuffer): This method is available in java.util.BitSet class of Java.
Syntax:
BitSet java.util.BitSet.valueOf(ByteBuffer bb)
This method takes one argument of type ByteBuffer as its parameter. This method returns a new bit set containing all the bits in the given bytebuffer between its position and limit.
Parameters: One parameter is required for this method.
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.
Returns: a BitSet containing all the bits in the buffer in the specified range.
Exceptions: NA
Approach
Java
import java.nio.ByteBuffer;import java.util.BitSet;public class BitSetvalueOfByteBuffer {public static void main(String[] args) {byte array[] = { 1, 4, 6, 7 };ByteBuffer byteBuffer = ByteBuffer.wrap(array);System.out.println(BitSet.valueOf(byteBuffer));}}
Output:
{0, 10, 17, 18, 24, 25, 26}
No comments:
Post a Comment