Java BitSet intersects() methodLast Updated : 17 Mar 2025 The intersects(BitSet set) method of Java BitSet class returns Boolean value true or false on the basis of whether parameter BitSet has intersected with this BitSet or not. It returns true if the specified BitSet set is also true in this BitSet. Syntax:Parameter:
Returns:It returns a Boolean value true or false on the basis of whether parameter BitSet has intersected with this BitSet or not. Exception:NullPointerException - If null parameter will pass in the method. Compatibility Version:Java 1.4 and above Example 1Output:
bitset1: {1, 2, 3, 4}
bitset2: {1, 2, 6, 7}
bitset3: {5, 6, 7, 8}
intersected result between bitset1 and bitset2: true
intersected result between bitset1 and bitset3: false
Example 2This method throws a NullPointerException if we pass a null parameter. Output:
Exception in thread "main" java.lang.NullPointerException
at java.util.BitSet.intersects(Unknown Source)
at BitSetEntersectsExample2.main(BitSetEntersectsExample2.java:14)
bitset1: {1, 2, 3, 4}
Next TopicJava-bitset-hashcode-method |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India