BitSet int length() Method Example Program


Returns the "logical size" of this BitSet: the index of the highest set bit in the BitSet plus one. Returns zero if the BitSet contains no set bits.

Program

package com.candidjava;

import java.util.BitSet;

/**
 * @author :vinod kumar v
 * @description :The BitSet.isEmpty() method returns true if this BitSet
 *              contains no bits that are set to true.
 * */

public final class BitSetLength {
	public static void main(String[] args) {

		BitSet obj = new BitSet(8);
		BitSet obj1 = new BitSet(8);

		obj.set(0);
		obj.set(1);
		obj.set(2);
		obj.set(3);

		obj1.set(2);
		obj1.set(4);
		obj1.set(6);
		obj1.set(8);

		System.out.println("The Value in obj:" + obj);
		System.out.println("The Value in obj1" + obj1);

		System.out.println(" the set length is:" + obj.length());
		System.out.println("the set length is:" + obj1.length());
	}
}

Output

The Value in obj:{0, 1, 2, 3}
The Value in obj1{2, 4, 6, 8}
 the set length is:4
the set length is:9

Explanation

public int length()
Returns the "logical size" of this BitSet: the index of the highest set bit in the BitSet plus one. Returns zero if the BitSet contains no set bits.
Returns:
the logical size of this BitSet


Related Post

Comments


©candidjava.com