title: How does the cardinality work in Java BitSet?
body: <pre><code>import java.util.*;
  public class Main {
  public static void main(String[] args)
  {
  
  BitSet bs1 = new BitSet();
  BitSet bs2 = new BitSet();
  
  
  bs1.set(0);
  bs1.set(1);
  bs1.set(2);
  bs1.set(4);
  
  bs2.set(0);
  bs2.set(0);
  bs2.set(0);
  bs2.set(0);
  bs2.set(0);
  bs2.set(0);
  
  
  System.out.println(&quot;bs1 : &quot; + bs1);
  System.out.println(&quot;bs2 : &quot; + bs2);
  
  
  
  System.out.println(bs1.cardinality());
  System.out.println(bs2.cardinality());
  
  }
  }
  </code></pre>
  <p>In this above code, the cardinality of bitset bs1 is found to be 4 and the bs2 is found to be 1. How does the cardinality come as 1 for bs2?</p>