BitSet是java.util包中定義的類。它創建一個由0和1表示的位數組。
句法
public boolean intersects(BitSet set)
參數:該方法接受強製性參數集,該參數集是要檢查交集的BitSet。
返回:該方法返回一個布爾值,指示此BitSet是否與指定的BitSet相交
說明:如果指定的BitSet具有設置為true的任何位,並且在此BitSet中也設置為true,則該方法返回true,否則返回false。
例子:
Input: set1:{1, 2, 4} set2:{} Output: false
// Java program illustrating Bitset Class functions.
import java.util.*;
public class GFG {
public static void main(String[] args)
{
// Constructors of BitSet class
BitSet bs1 = new BitSet();
BitSet bs2 = new BitSet();
BitSet bs3 = new BitSet();
/* set is BitSet class method
expalined in next articles */
bs1.set(0);
bs1.set(1);
bs1.set(2);
bs1.set(4);
// assign values to bs2
bs2.set(4);
bs2.set(6);
bs2.set(5);
bs2.set(1);
bs2.set(2);
bs2.set(3);
// Printing the 2 Bitsets
System.out.println("bs1:" + bs1);
System.out.println("bs2:" + bs2);
System.out.println("bs3:" + bs3);
// Performing intersects on two bitset
System.out.println("bs1 intersection bs3 = "
+ bs1.intersects(bs2));
System.out.println("bs3 intersection bs1 = "
+ bs3.intersects(bs1));
}
}
輸出:
bs1:{0, 1, 2, 4} bs2:{1, 2, 3, 4, 5, 6} bs3:{} bs1 intersection bs3 = true bs3 intersection bs1 = false
相關文章:
相關用法
- Java BitSet or()用法及代碼示例
- Java BitSet cardinality()用法及代碼示例
- Java Java.util.BitSet.clear()用法及代碼示例
- Java Java.util.BitSet.set()用法及代碼示例
- Java Java.util.BitSet.flip()用法及代碼示例
- Java BitSet previousClearBit()用法及代碼示例
- Java BitSet nextSetBit()用法及代碼示例
- Java BitSet nextClearBit()用法及代碼示例
- Java BitSet isEmpty()用法及代碼示例
- Java BitSet previousSetBit()用法及代碼示例
- Java BitSet toString()用法及代碼示例
注:本文由純淨天空篩選整理自barykrg大神的英文原創作品 Java BitSet | intersects()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。