Java位集 |或者()
先决条件: Java BitSet |设置 1
BitSet 是在Java.util包中定义的一个类。它创建一个由布尔值表示的位数组。
它执行调用者 BitSet 与被调用 BitSet 的逻辑或。此 BitSet 仅在它为 true 并且 BitSet 参数的值为 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
// 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);
}
}
输出:
set1 : {8, 21, 23, 45}
set2 : {3, 12, 21, 78, 89, 93}
After Performing OR :
{3, 8, 12, 21, 23, 45, 78, 89, 93}
相关文章 :
- Bitset 类示例集 1
- Bitset 类示例集 2
- Bitset 类示例集 3