Java BitSet | or()

Prerequisite : Java BitSet | Set 1

BitSet 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.


public void and(BitSet set);


Input : 
set1 : {1, 2, 4}
set2 : {2, 3, 4}

Output : After performing set1.or(set2)
set2 : {1, 2, 3, 4}






// 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
        expalined in next articles */
        // assign values to set2
        // Printing the 2 Bitsets
        System.out.println("set1 : " + set1);
        System.out.println("set2 : " + set2);
        // Performing logical AND
        // on set2 set with set1
        // set2 set after Performing AND
        System.out.println("After Performing OR :");



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 :

  1. Bitset Class Examples Set 1
  2. Bitset Class Examples Set 2
  3. Bitset Class Examples Set 3

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.