title: How do addAll in TreeSet and HashSet really work?
body: <p>When I added my datas on the treeSet I lost almost all my datas. It seems that I have only the first element of my set.</p>
  
  <p>I read this question <a href="https://stackoverflow.com/questions/1463284/hashset-vs-treeset">Hashset vs Treeset</a> for an code optimization and I tried to do something like them. But I didn't really succeed.</p>
  
  <p>Input : </p>
  
  <pre><code>int iValue = 0;
  
      HashSet&lt;TagResult&gt; results = new HashSet&lt;TagResult&gt;();
      for(Document doc : docs) {
          NodeList nList = doc.getElementsByTagName("TEXT");
  
          for (int temp = 0; temp &lt; nList.getLength(); temp++) {
              Node nNode = nList.item(temp);
              if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                  Element eElement = (Element) nNode;
                  iValue = searchWords.searchOnTag(eElement, szSearch);
                  if(iValue &gt; 0) {
                      results.add(new TagResult(eElement, iValue));
                  }
              }
          }
      }
      System.out.println("Set :\n-------------------------");
      for(TagResult result : results) {
          System.out.println(getTagValue("Tag",result.getElement()));
      }
      Set&lt;TagResult&gt; sortedResult = new TreeSet&lt;TagResult&gt;(new Comparator&lt;TagResult&gt;() {
  
          public int compare(TagResult e1, TagResult e2) {
              return e2.getValue() - e1.getValue();
          }
      });
  
      sortedResult.addAll(results);
  
      System.out.println("Sorted Result :\n-------------------------");
      for(TagResult result : sortedResult) {
          System.out.println(getTagValue("Tag",result.getElement()));
  }
  </code></pre>
  
  <p>The execution result give me that :</p>
  
  <p>Output</p>
  
  <p>Set :</p>
  
  <pre><code>TXT_KEY_RELIGION_POSITIF_MEDIAN_05
  TXT_KEY_RELIGION_POSITIF_MEDIAN_02
  TXT_KEY_RELIGION_POSITIF_04
  TXT_KEY_RELIGION_POSITIF_06
  TXT_KEY_RELIGION_POSITIF_05
  TXT_KEY_RELIGION_POSITIF_03
  TXT_KEY_RELIGION_POSITIF_MEDIAN_06
  TXT_KEY_RELIGION_POSITIF_MEDIAN_01
  TXT_KEY_RELIGION_POSITIF_MEDIAN_04
  TXT_KEY_RELIGION_POSITIF_MEDIAN_08
  TXT_KEY_RELIGION_POSITIF_MEDIAN_03
  TXT_KEY_RELIGION_POSITIF_02
  TXT_KEY_RELIGION_POSITIF_07
  TXT_KEY_RELIGION_POSITIF_01
  TXT_KEY_RELIGION_POSITIF_MEDIAN_09
  TXT_KEY_RELIGION_POSITIF_MEDIAN_07
  </code></pre>
  
  <p>Sorted Result :</p>
  
  <pre><code>TXT_KEY_RELIGION_POSITIF_MEDIAN_05
  </code></pre>
  
  <p>I don't understand why I have this problem.</p>