BitSet void set(int bitIndex) Method Example Program


Sets the bit at the specified index to true.

Program

package com.candidjava;

import java.util.BitSet;

/**
 * @author :vinod kumar v
 * @description :set(int bitIndex) Sets the bit at the specified index to true.
 * */

public final class BitSetset {
	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.or(obj1);

		System.out.println("value in both obj and obj1 is:" + obj);
	}
}

Output

The Value in obj:{0, 1, 2, 3}
The Value in obj1{2, 4, 6, 8}
value in both obj and obj1 is:{0, 1, 2, 3, 4, 6, 8}

Explanation

public void set(int bitIndex)
Sets the bit at the specified index to true.
Parameters:
bitIndex - a bit index
Throws:
IndexOutOfBoundsException - if the specified index is negative


Related Post

Comments


©candidjava.com