Compares this object against the specified object. The result is true if and only if the argument is not null and is a Bitset object that has exactly the same set of bits set to true as this bit set. That is, for every nonnegative int index k,
((BitSet)obj).get(k) == this.get(k)
must be true. The current sizes of the two bit sets are not compared.
Program
package com.candidjava;
import java.util.BitSet;
/**
* @author :vinod kumar v
* @description :The BitSet.equals(Object obj) method compares this object
* against the specified object. The result is true if and only if
* the argument is not null and is a Bitset object that has exactly
* the same set of bits set to true as this bit set. That is, for
* every nonnegative int index k,
* */
public final class BitSetEquals {
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("" + obj.equals(obj1));
obj1 = obj;
System.out.println("" + obj.equals(obj1));
}
}
Output
The Value in obj:{0, 1, 2, 3}
The Value in obj1{2, 4, 6, 8}
false
true
Explanation
public boolean equals(Object obj)
Compares this object against the specified object. The result is true if and only if the argument is not null and is a Bitset object that has exactly the same set of bits set to true as this bit set. That is, for every nonnegative int index k,
((BitSet)obj).get(k) == this.get(k)
must be true. The current sizes of the two bit sets are not compared.