BitSet void set(int fromIndex,int toIndex, boolean value) Method Example Program


Sets the bits from the specified fromIndex (inclusive) to the specified toIndex (exclusive) to the specified value.

Program

package com.candidjava;

import java.util.BitSet;

/**
 * @author :vinod kumar v
 * @description :The BitSet.set(int fromIndex,int toIndex,boolean value) method
 *              sets the bits from the specified fromIndex (inclusive) to the
 *              specified toIndex (exclusive) to the specified value.
 * */

public final class BitSetSetFromToIndex {
	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);

		obj.set(1, 10, false);
		obj1.set(5, 15, true);

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

Output

The Value in obj:{0, 1, 2, 3}
The Value in obj1{2, 4, 6, 8}
The Value in obj:{0}
The Value in obj1{2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}

Explanation

public void set(int fromIndex, int toIndex, boolean value)
Sets the bits from the specified fromIndex (inclusive) to the specified toIndex (exclusive) to the specified value.
Parameters:
fromIndex - index of the first bit to be set
toIndex - index after the last bit to be set
value - value to set the selected bits to
Throws:
IndexOutOfBoundsException - if fromIndex is negative, or toIndex is negative, or fromIndex is larger than toIndex


Related Post

Comments


©candidjava.com