# BitSet void xor(BitSet set) Method Example Program

Performs a logical XOR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value true if and only if one of the following statements holds:
The bit initially has the value true, and the corresponding bit in the argument has the value false.
The bit initially has the value false, and the corresponding bit in the argument has the value true.

#### Program

```package com.candidjava;

import java.util.BitSet;
/**
* @author : vinod kumar v
* @description :The java.util.BitSet.xor(BitSet set) method performs a logical XOR of this bit set with the bit set argument.
* **/
public class BitSetXOR {

public static void main(String[] args) {

BitSet bitset1 = new BitSet(8);
BitSet bitset2 = new BitSet(8);

bitset1.set(0);
bitset1.set(1);
bitset1.set(2);
bitset1.set(3);
bitset1.set(4);
bitset1.set(5);

bitset2.set(2);
bitset2.set(4);
bitset2.set(6);
bitset2.set(8);
bitset2.set(10);

System.out.println("Bitset1:" + bitset1);
System.out.println("Bitset2:" + bitset2);

bitset1.xor(bitset2);
System.out.println("" + bitset1);

}
}
```

#### Output

Bitset1:{0, 1, 2, 3, 4, 5}
Bitset2:{2, 4, 6, 8, 10}
{0, 1, 3, 5, 6, 8, 10}

#### Explanation

public void xor(BitSet set)
Performs a logical XOR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value true if and only if one of the following statements holds:
The bit initially has the value true, and the corresponding bit in the argument has the value false.
The bit initially has the value false, and the corresponding bit in the argument has the value true.
Parameters:
set - a bit set

Related Post