BitSet int nextClearBit(int fromIndex) Method Example Program


Returns the index of the first bit that is set to false that occurs on or after the specified starting index.

Program

package com.candidjava;

import java.util.BitSet;

/**
 * @author :vinod kumar v
 * @description :The BitSet.nextClearBit(int fromIndex) method returns the index
 *              of the first bit that is set to false that occurs on or after
 *              the specified starting index.
 * */

public final class BitSetNextClear {
	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 nextclear bit is:" + obj.nextClearBit(0));
		System.out.println("the nextclear bit is:" + obj1.nextClearBit(6));
	}
}

Output

The Value in obj:{0, 1, 2, 3}
The Value in obj1{2, 4, 6, 8}
 the nextclear bit is:4
the nextclear bit is:7

Explanation

public int nextClearBit(int fromIndex)
Returns the index of the first bit that is set to false that occurs on or after the specified starting index.
Parameters:
fromIndex - the index to start checking from (inclusive)
Returns:
the index of the next clear bit
Throws:
IndexOutOfBoundsException - if the specified index is negative


Related Post

Comments


©candidjava.com