I have a bitset and I want to check whether a bit at a specific index is zero or one.
Asked
Active
Viewed 956 times
-3
-
I got it I was confused while reading javadocs..Please close it – Soul Enrapturer Jan 01 '13 at 12:47
1 Answers
6
Just use .get()
:
return theSet.get(index);
It returns true
if the bit is set and false
otherwise.

fge
- 119,121
- 33
- 254
- 329
-
+1 Technically, you don't need to know whether a 0 or 1 is used or something else. BitSet will tell you if the "bit" is *set or clear*. For example if you ask for a bit, beyond the size of the BitSet, e.g. `new BitSet(32).get(64)` will return false even though there is no 0 or 1 as such. – Peter Lawrey Jan 01 '13 at 12:50