Java BitSet andNot() 方法

7 Jan 2025 | 1 分钟阅读

Java BitSet 类的 andNot() 方法用于清除此 BitSet 中与指定 BitSet 中设置为 true 的对应位相同的位。

语法

参数

数据类型参数描述
BitSetset这是一个位集合。

返回值

不适用

Exception

NullPointerException - 如果向该方法传递了 null 参数。

兼容版本

Java 1.2 及以上版本

示例 1

输出

bitset1: {0, 1, 2, 3, 4}
bitset2: {1, 3, 5, 6, 7}
result bitset after andNot: {0, 2, 4}

示例 2

如果传入 null 参数,此方法将抛出 NullPointerException。

输出

Exception in thread "main" java.lang.NullPointerException
	at java.util.BitSet.andNot(Unknown Source)
	at BitSetAndNotExample2.main(BitSetAndNotExample2.java:16)
bitset1: {0, 1, 2, 3, 4}