title: why does TreeSet remove duplicates when they are unequal?
body: <p>Friends, I am having a problem in getting entire data using <code>TreeSet</code>. I have sorted the <code>TreeSet</code> on some same values.</p>
  
  <p>here is my code:</p>
  
  <p><code>MyCars</code> class:</p>
  
  <pre><code>class MyCars implements Comparable&lt;MyCars&gt;{
  
      private String number;
      private int yearModel;
      private double horsePower;
  
      public String getNumber() {
          return number;
      }
      public void setNumber(String number) {
          this.number = number;
      }
      public int getYearModel() {
          return yearModel;
      }
      public void setYearModel(int yearModel) {
          this.yearModel = yearModel;
      }
      public double getHorsePower() {
          return horsePower;
      }
      public void setHorsePower(double horsePower) {
          this.horsePower = horsePower;
      }
      @Override
      public int compareTo(MyCars c) {
          return Double.compare(this.horsePower,c.getHorsePower());
      }
  }
  </code></pre>
  
  <p><code>SortTest</code> class:</p>
  
  <pre><code>public class SortTest {
  
      void GoForSort(){
          Set dataStructure=new TreeSet();
  
          MyCars c1=new MyCars();
          c1.setNumber("SRT-Viper123");
          c1.setYearModel(2013);
          c1.setHorsePower(450.00);
  
          MyCars c2=new MyCars();
          c2.setNumber("Chevrolet-Corvette901");
          c2.setYearModel(2012);
          c2.setHorsePower(450.00);
  
          MyCars c3=new MyCars();
          c3.setNumber("Ford-Mustang678");
          c3.setYearModel(2014);
          c3.setHorsePower(455.00);
  
          dataStructure.add(c1);
          dataStructure.add(c2);
          dataStructure.add(c3);
  
          Iterator&lt;MyCars&gt; it=dataStructure.iterator();
          while(it.hasNext()){
              MyCars c=it.next();
              System.out.println(c.getNumber()+"\t"+c.getHorsePower()+"\t"+c.getYearModel());
          }
  
      }
      public static void main(String[] args) {
          SortTest st=new SortTest();
          st.GoForSort();
  
      }
  
  }
  </code></pre>
  
  <p>As you can see I have sorted the <code>TreeSet</code> on the basis of horsePower. And I have given SAME value for horse-power to two objects.</p>
  
  <p>Here is the output I get:</p>
  
  <pre><code>SRT-Viper123    450.0   2013
  Ford-Mustang678 455.0   2014
  </code></pre>
  
  <p>But I also want <code>Chevrolet-Corvette901</code> to come in this set of output. Why I am not getting it. </p>
  
  <p>Is there any way to include that also? Because I found there was NO Problem when I change my collection to <code>ArrayList</code>. Does <code>TreeSet</code> sorts only unique elements? </p>
  
  <p>Is there any trick to get &amp; print all objects during <code>Iteration</code> regardless of their uniqueness in <code>TreeSet</code>...</p>