Returns a new bit set containing all the bits in the given long buffer between its position and limit.
Program
package com.candidjava;
import java.nio.ByteBuffer;
/**
* @author : vinod kumar v
* @description :Returns a new bit set containing all the bits in the given long
* buffer between its position and limit.
* */
public class BitSetStaticLongBuffer {
private static ByteBuffer longBuffer = ByteBuffer.allocate(Long.BYTES);
private static ByteBuffer intBuffer = ByteBuffer.allocate(Integer.BYTES);
private static byte[] longToByteArray(long value) {
longBuffer.putLong(0, value);
return longBuffer.array();
}
private static int byteArrayToInt(byte[] array) {
intBuffer.put(array, 0, array.length);
intBuffer.flip();
return intBuffer.getInt();
}
}
Output
Bitset1:{0, 1, 2, 3, 4, 5}
Bitset2:{2, 4, 6, 8, 10}
{0, 1, 3, 5, 6, 8, 10}
Explanation
public static BitSet valueOf(LongBuffer lb)
Returns a new bit set containing all the bits in the given long buffer between its position and limit.
The long buffer is not modified by this method, and no reference to the buffer is retained by the bit set.
Parameters:
lb - a long 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