Java BitSet cardinality() methodThe cardinality() method of Java BitSet class returns the number of bits set which are true in this BitSet. Syntax:Parameter:NA Returns:The cardinality() method returns the number of bits set which are true in this BitSet. Exception:NA Compatibility Version:Java 1.4 and above Example 1Output: bitset: {0, 1, 2, 5, 6} number of true bits: 5 bitset after clear index 2: {0, 1, 5, 6} number of true bits after clear index 2: 4 Example 2In this example, we are creating a BitSet object using string of bits as input and applying cardinality() method on it. Output: bitset: {0, 2, 4} number of true bits: 3 Next TopicJava-bitset-clear-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