hai friends, The question given below was from the Marcus Green mock test1. iam unable to get the question, plz explain it. Which of the following most closely describes a bitset collection? 1) A class that contains groups of unique sequences of bits 2) A method for flipping individual bits in instance of a primitive type 3) An array of boolean primitives that indicate zeros or ones 4) A collection for storing bits as on-off information, like a vector of bit
Ah, but BitSet is a class left over from Java 1.0 and does not implement the Set interface. It is really more like a BitVector - just one more example of naming confusion created as Java grew. Therefore, answer 3 is correct. Simply looking at the JavaDocs for java.util.BitSet would have revealed this. You really should make a habit of it. Bill
This question threw me too. It smells like a set but isn't one. How annoying. But there is another odd thing in answer three:
3) An array of boolean primitives that indicate zeros or ones
As Bill suggested, I looked BitSet up in JavaDoc and it says
Each component of the bit set has a boolean value.
Now we all know that you cannot assign either a zero or a one to a boolean. So anwser three still seems a bit off. In defense of the wording, the class has methods that set, flip and clear bits which sounds more like zeroes and ones than booleans. Another confusing detail: JavaDoc says "This class implements a vector of bits...". This is not to be confused with java.util.Vector which takes objects, not primitives. So BitSet is a vector of bits that is neither a Set nor a Vector. As a language evolves you often see odd quirks like this. Even Java has its share.
I haven't gotten to be "the focus police" for a while The exam creators didn't consider BitSet to be part of the "collections framework" as it doesn't implement Collection, Set, List, or Map. So you can relax, and not worry about BitSets for the exam. If, on the other hand, you're goal is to memorize the entire API, then BitSet is a card carrying member
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)