Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The documentation for a <a href="http://docs.oracle.com/javase/7/docs/api/java/util/BitSet.html" rel="nofollow"><code>BitSet</code></a> pretty clearly implies that the implementation isn't necessarily an actual boolean array. In particular:</p> <blockquote> <p>Every bit set has a current size, which is the number of bits of space currently in use by the bit set. Note that the size is related to the implementation of a bit set, so it may change with implementation. The length of a bit set relates to logical length of a bit set and is defined independently of implementation.</p> </blockquote> <p>The source for Java library classes is openly available and you can easily <a href="http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/util/BitSet.java" rel="nofollow">check this for yourself</a>. In particular:</p> <pre><code>The internal field corresponding to the serialField "bits". 89 90 private long[] words; </code></pre> <p>As for speed; profile it. It depends on what you are doing. In general, don't think about speed ahead of time; use whichever tool makes the most sense semantically and leads to the clearest code. Optimize only after observing that your performance requirements aren't being met and identifying the bottlenecks.</p> <p>In any case, obviously, I'd presume that a direct access to a value in a boolean array is faster than finding the bit in a long array, but performing a bitwise OR on two long values is faster than performing a logical OR on 64 boolean values. Think about it a little. For example:</p> <pre><code>613 public boolean get(int bitIndex) { 614 if (bitIndex &lt; 0) 615 throw new IndexOutOfBoundsException("bitIndex &lt; 0: " + bitIndex); 616 617 checkInvariants(); 618 619 int wordIndex = wordIndex(bitIndex); 620 return (wordIndex &lt; wordsInUse) 621 &amp;&amp; ((words[wordIndex] &amp; (1L &lt;&lt; bitIndex)) != 0); 622 } </code></pre> <p>As for other differences, obviously the API is different. <code>BitSet</code> provides a number of bitwise operations that you may need to use. A <code>boolean</code> array is an array. The one that works best for you will depend on your specific application requirements.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload