Java BitSet | XOR Last Updated : 31 Jul, 2021 Comments Improve Suggest changes Like Article Like Report BitSet is a class defined in the java.util package. It creates an array of bits represented by boolean values. Syntax public void xor(BitSet set); Explanation: The method performs a logical XOR, such that in the BitSet, a bit is set if and only if the bit initially has the value true, and the corresponding bit in the argument has the value false, and vice-versa. Examples: Input : set1 : {1, 2, 4} set2 : {2, 3, 4} Output : After performing st1.xor(set2) set2 : {1, 3} Program: Java // Java program illustrating Bitset Class Function. import java.util.*; public class GFG { public static void main(String[] args) { // Constructors of BitSet class BitSet bs1 = new BitSet(); BitSet bs2 = new BitSet(6); /* set is BitSet class method explained in next articles */ bs1.set(0); bs1.set(1); bs1.set(2); bs1.set(4); // assign values to bs2 bs2.set(4); bs2.set(6); bs2.set(5); bs2.set(1); bs2.set(2); bs2.set(3); // Printing the 2 Bitsets System.out.println("bs1 : " + bs1); System.out.println("bs2 : " + bs2); // Performing logical AND // on bs2 set with bs1 bs2.xor(bs1); // bs2 set after Performing AND System.out.println("After Performing XOR :"); System.out.println(bs2); } } Output: bs1 : {0, 1, 2, 4} bs2 : {1, 2, 3, 4, 5, 6} After Performing XOR : {0, 3, 5, 6} Related Articles : Bitset Class Examples Set 1Bitset Class Examples Set 2Bitset Class Examples Set 3 Comment More infoAdvertise with us Next Article Java BitSet | XOR B barykrg Follow Improve Article Tags : Misc Java Java - util package Bitwise-XOR Java-Functions Java-BitSet +2 More Practice Tags : JavaMisc Similar Reads Java BitSet | or() Prerequisite : Java BitSet | Set 1BitSet is a class defined in the java.util package. It creates an array of bits represented by boolean values. It performs a logical OR of the caller BitSet with the called BitSet. This BitSet gets set only when it is true and the BitSet argument has the value true. 2 min read Java BitSet | and Prerequisite : Java BitSet | Set 1BitSet is a class defined in the java.util package. It creates an array of bits represented by boolean values.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 i 2 min read Bitwise Operators in Java In Java, Operators are special symbols that perform specific operations on one or more than one operands. They build the foundation for any type of calculation or logic in programming.There are so many operators in Java, among all, bitwise operators are used to perform operations at the bit level. T 6 min read BigInteger xor() Method in Java Prerequisite: BigInteger Basics The xor(BigInteger val) method returns bitwise-XOR of two bigIntegers. This method returns a negative BigInteger if and only if exactly one of the current bigInteger and the bigInteger passed in parameter id negative. The xor() method of BigInteger class apply bitwise 2 min read Java BitSet | intersects() BitSet is a class defined in the java.util package. It creates an array of bits represented by 0s and 1s. Syntax public boolean intersects(BitSet set) Parameter: The method accepts a mandatory parameter set, which is the BitSet to be checked for intersection. Returns: The method returns a boolean in 2 min read BitSet isEmpty() method in Java BitSet is a class defined in the java.util package. It creates an array of bits represented by boolean values. Prerequisite : Java BitSet | Set 1 Bitset.isEmpty() This method is used to check if there are any bits that are set to true, in the specified BitSet. This method returns true if this BitSet 2 min read || operator in Java || is a type of Logical Operator and is read as "OR OR" or "Logical OR". This operator is used to perform "logical OR" operation, i.e. the function similar to OR gate in digital electronics. One thing to keep in mind is the second condition is not evaluated if the first one is true, i.e. it has a sh 1 min read Java BitSet | cardinality() BitSet is a class defined in the java.util package. It creates an array of bits represented by 0s and 1s. Syntax public int cardinality() Explanation: The method returns the number of 1s in this BitSet. Examples: Input : set1 : {1, 2, 4} set2 : {} Output : 3 0 Java // Java program illustrating Bitse 1 min read Java Programming Basics Java is one of the most popular and widely used programming language and platform. A platform is an environment that helps to develop and run programs written in any programming language. Java is fast, reliable and secure. From desktop to web applications, scientific supercomputers to gaming console 4 min read Introduction to Java Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995. It is platform-independent, which means we can write code once and run it anywhere using the Java Virtual Machine (JVM). Java is mostly used for building desktop applications, web applications, Android 4 min read Like