BitSet void and(BitSet set) Method Example Program


Performs a logical AND of this target bit set with the argument bit set. This bit set is modified so that each bit in it has the value true if and only if it both initially had the value true and the corresponding bit in the bit set argument also had the value true.

Program

package com.candidjava;

import java.util.BitSet;

/**
 * @author :vinod kumar v
 * @description :The BitSet.and(BitSet set) method performs a logical
 *              AND of this target bit set with the argument bit set. This bit
 *              set is modified so that each bit in it has the value true if and
 *              only if it both initially had the value true and the
 *              corresponding bit in the bit set argument also had the value
 *              true.
 * */

public final class BitSetAnd {
	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.and(obj1);
		System.out.println("" + obj);

	}
}

Output

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

Explanation

public void and(BitSet set)
Performs a logical AND of this target bit set with the argument bit set. This bit set is modified so that each bit in it has the value true if and only if it both initially had the value true and the corresponding bit in the bit set argument also had the value true.
Parameters:
set - a bit set


Related Post

Comments


©candidjava.com