BitSet是java.util包中定义的类。它创建一个由布尔值表示的位数组。它执行调用方BitSet与被调用BitSet的逻辑或。仅当它为true且BitSet参数的值为true时,才会设置此BitSet。
用法:
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 */
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);
}
}
输出:
set1:{8, 21, 23, 45}
set2:{3, 12, 21, 78, 89, 93}
After Performing OR:
{3, 8, 12, 21, 23, 45, 78, 89, 93}
相关文章: