Java BitSet nextClearBit() method7 Jan 2025 | 2 min read The nextClearBit(int fromIndex) method of Java BitSet class returns the index of first bit which is set to false that occurs on or after the specified index. Syntax:Parameter:
Returns:This method returns the index of the next clear bit. Exception:IndexOutOfBoundsException - throw an exception if the specified index is negative. Compatibility Version:Java 1.4 and above Example 1Output:
bitset: {0, 1, 3, 4}
clear bit next to 3: 5
clear bit next to 0: 2
clear bit next to 2: 2
Example 2The nextClearBit(int fromIndex) method throws an exception if the specified index is negative. Output:
Exception in thread "main" java.lang.IndexOutOfBoundsException: fromIndex < 0: -1
at java.util.BitSet.nextClearBit(Unknown Source)
at BitSetNextClearBitExample2.main(BitSetNextClearBitExample2.java:14)
bitset: {0, 1, 3, 4}
Next TopicJava-bitset-length-method |
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India