title: TreeSet not adding all elements?
body: <p>I have been looking into the speeds of different Java collection types and have come across something weird. I am adding 1,000,000 objects from a static array to a different collection type and returning the time required. This part of the code works fine. </p>
  
  <p>Under further investigation I noticed that the <code>TreeSet</code> is not receiving all of the 1,000,000 objects, and is receiving a different amount each time. Below is the method to transfer the objects from an array to the <code>TreeSet</code>:</p>
  
  <pre><code>    public int treeSet(int num)
      {
         Date before = new Date();
  
         for(int i=0; i&lt;num; i++) 
         {
             treeSet.add(personsArray[i]);
         }
  
         Date after = new Date();
         return (int) (after.getTime() - before.getTime());
      }
  </code></pre>
  
  <p>Below is the code which calls the treeSet() method and tests for its size.</p>
  
  <pre><code>    System.out.println("\tTree set with 1,000,000 objects--" + t.treeSet(1000000));
      System.out.println("Tree set contains " + t.treeSet.size() + " elements");
  </code></pre>
  
  <p>The output of this is:</p>
  
  <pre><code>    Tree set with 1,000,000 objects--1192
      Tree set contains 975741 elements
  </code></pre>
  
  <p>I'm hoping someone can explain to me why the <code>TreeSet</code> is not receiving all of the objects and why it is receiving inconsistent amounts.</p>