BitSet static BitSet valueOf(long[] longs) Method Example Program


Returns a new bit set containing all the bits in the given long array.

Program

package com.candidjava;

import java.util.BitSet;

/**
 * @author : vinod kumar v
 * @description :Returns a new bit set containing all the bits in the given long
 *              array.
 **/
public class BitSetStaticValueOfLongLongs {
	public static void main(String[] args) throws Exception {
		byte b = Integer.valueOf("00010110", 2).byteValue();
		BitSet bs = BitSet.valueOf(new byte[] { b });
		System.out.println("toString : " + bs.toString());
	}
}

Output

toString : {1, 2, 4}

Explanation

public static BitSet valueOf(long[] longs)
Returns a new bit set containing all the bits in the given long array.
More precisely, 
BitSet.valueOf(longs).get(n) == ((longs[n/64] & (1L<<(n%64))) != 0) 
for all n < 64 * longs.length.

This method is equivalent to BitSet.valueOf(LongBuffer.wrap(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


Related Post

Comments


©candidjava.com