Java BitSet get() methodThe get() method of Java BitSet class returns the bit value. There are two overloaded get() method available in BitSet class. 1. Java BitSet get(int bitIndex) methodThe get(int bitIndex) method returns the bit value of the specified index. It returns true if the index bitIndex is currently set in the BitSet, otherwise returns false. 2. Java BitSet get(int fromIndex, int toIndex) methodThe get(int bitIndex) method returns a new BitSet of bits from specified inclusive index fromIndex to exclusive index toIndex of the current BitSet. Syntax:Parameter:
Returns:
Exception:IndexOutOfBoundsException - If any of the following statement becomes true:
Compatibility Version:
Example of Java BitSet get(int bitIndex) methodExample 1Output: bitset: {0, 1, 3, 4} bitset at index 0: true bitset at index 1: true bitset at index 2: false Example 2The get(int bitIndex) method throw an exception, if passing a negative int parameter. Output: bitset: {0, 1, 3, 4} Exception in thread "main" java.lang.IndexOutOfBoundsException: bitIndex < 0: -1 at java.util.BitSet.get(Unknown Source) at BitSetGetExample2.main(BitSetGetExample2.java:11) Example of Java BitSet get(int fromIndex, int toIndex) methodExample 3Output: bitset: {0, 1, 3, 4} bitset at index 0,3: {0, 1} Example 4The get(int fromIndex, int toIndex) method throw an exception, if fromIndex is greater than the index toIndex. Output: bitset: {0, 1, 3, 4} Exception in thread "main" java.lang.IndexOutOfBoundsException: fromIndex: 3 > toIndex: 0 at java.util.BitSet.checkRange(Unknown Source) at java.util.BitSet.get(Unknown Source) at BitSetGetExample4.main(BitSetGetExample4.java:12) Next TopicJava-bitset-equals-method |
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