title: What is size of my Bitset?
body: <p>I want to store <code>System.currentTimeInMillis</code> in memory with minimum space possible. because I have to store millions of them in memory.</p>
  
  <p>I converted it to <code>binaryString</code> which gave me <code>41 bits</code></p>
  
  <p>Here is my program</p>
  
  <pre><code>public class BitSetSize {
      public static void main(final String[] args) {
          final long currentTimeMillis = System.currentTimeMillis();
          final String currentTimeToBinaryString = Long.toBinaryString(currentTimeMillis);
          System.out.println("Size in bits: " + currentTimeToBinaryString.length());
  
          final BitSet bitSet = BitSet.valueOf(new long[]{currentTimeMillis});
          System.out.println("Bitset length: " + bitSet.length());
          System.out.println("Bitset size: " + bitSet.size());
  
          System.out.println("Size of biset object(bytes): " + MemoryMeasurer.measureBytes(bitSet));
      }
  }
  </code></pre>
  
  <p>But when I run it I get  </p>
  
  <pre><code>Size in bits: 41
  Bitset length: 41
  Bitset size: 64
  Size of biset object(bytes): 48
  </code></pre>
  
  <p><strong>Question</strong><br>
  - Why does <code>bitSet.length()</code> and <code>bitSet.size()</code> differ? I assume <code>length()</code> is correct?<br>
  - I am using <a href="https://stackoverflow.com/a/9368930/379235">memory-measurer</a> to learn about the size of <code>bitSet</code>, but it tell me <code>48 bytes</code>, why is it not <code>(41/8) byte</code>?</p>
  
  <p>I am confused</p>