Thursday, September 25, 2025
HomeLanguagesJavaJava BitSet | or()

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

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

 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32319 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6682 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6795 POSTS0 COMMENTS
Ted Musemwa
7071 POSTS0 COMMENTS
Thapelo Manthata
6753 POSTS0 COMMENTS
Umr Jansen
6761 POSTS0 COMMENTS