Java BitSet | or() Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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.Syntax: public void and(BitSet set); Examples: Input : set1 : {1, 2, 4} set2 : {2, 3, 4} Output : After performing set1.or(set2) set2 : {1, 2, 3, 4} Program: Java // Java program illustrating Bitset Class or() function. import java.util.*; public class GFG { public static void main(String[] args) { // Constructors of BitSet class BitSet set1 = new BitSet(); BitSet set2 = new BitSet(6); /* set is BitSet class method explained in next articles */ set1.set(21); set1.set(45); set1.set(8); set1.set(23); // assign values to set2 set2.set(12); set2.set(89); set2.set(21); set2.set(78); set2.set(93); set2.set(3); // Printing the 2 Bitsets System.out.println("set1 : " + set1); System.out.println("set2 : " + set2); // Performing logical AND // on set2 set with set1 set2.or(set1); // set2 set after Performing AND System.out.println("After Performing OR :"); System.out.println(set2); } } Output: set1 : {8, 21, 23, 45} set2 : {3, 12, 21, 78, 89, 93} After Performing OR : {3, 8, 12, 21, 23, 45, 78, 89, 93} Related Articles : Bitset Class Examples Set 1Bitset Class Examples Set 2Bitset Class Examples Set 3 Comment More infoAdvertise with us Next Article Java BitSet | and B barykrg Follow Improve Article Tags : Misc Java Java - util package Java-BitSet Practice Tags : JavaMisc Similar Reads Java BitSet | XOR 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 corres 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 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 || 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 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 Like