title: HashSet removes duplicates but TreeSet does not?
body: <p>Output of below class is : 
  size is 3
  size is 1</p>
  
  <p>But if I change the TreeSet to a HashSet so line : </p>
  
  <pre><code>Set&lt;SuggestionDetailBean&gt; set = new TreeSet&lt;SuggestionDetailBean&gt;();
  </code></pre>
  
  <p>becomes</p>
  
  <pre><code>Set&lt;SuggestionDetailBean&gt; set = new HashSet&lt;SuggestionDetailBean&gt;();
  </code></pre>
  
  <p>the output is : 
  size is 3
  size is 2</p>
  
  <p>Shout using HashSet or TreeSet not change the size of Set ?
  Using HashSet seems to behave as expected because it is removing duplicates but when I use TreeSet the duplicates remain ?
  I think the hashcode and equals methods in SuggestionDetailBean are overriden correctly ?</p>
  
  <p>Here is the code : </p>
  
  <pre><code>public class TestSet {
  
      public static void main(String args[]){
  
          SuggestionDetailBean s = new SuggestionDetailBean();
          s.setTagList("teddst");
          s.setUrl("testurl");
  
          SuggestionDetailBean s2 = new SuggestionDetailBean();
          s2.setTagList("teddst");
          s2.setUrl("testurl");
  
          SuggestionDetailBean s3 = new SuggestionDetailBean();
          s3.setTagList("tessdafat");
          s3.setUrl("fdfaasdfredtestur ldd");
  
          List&lt;SuggestionDetailBean&gt; list = new ArrayList&lt;SuggestionDetailBean&gt;();
          list.add(s);
          list.add(s2);
          list.add(s3);
  
          Set&lt;SuggestionDetailBean&gt; set = new TreeSet&lt;SuggestionDetailBean&gt;();
          set.addAll(list);
  
          System.out.println("size is "+list.size());
          System.out.println("size is "+set.size());
  
      }
  
  }
  
  public class SuggestionDetailBean implements Comparable&lt;Object&gt; {
  
      private String url;
      private String tagList;
      private String numberOfRecommendations;
      private String date;
      private String time;
      private String summary;
      private String truncatedUrl;
  
  
      public void setTruncatedUrl(String truncatedUrl) {
  
          if(truncatedUrl.length() &gt; 20){
              truncatedUrl = truncatedUrl.substring(0, 20)+"...";
          }
  
          this.truncatedUrl = truncatedUrl;
      }
  
      public String getSummary() {
          if(summary == null){
              return "";
          }
          else {
              return summary;
          }
      }
  
      public void setSummary(String summary) {
          this.summary = summary;
      }
  
      public String getDate() {
          return date;
      }
  
      public void setDate(String date) {
          this.date = date;
      }
  
  
          public String getTime() {
              return time;
          }
  
          public String getTruncatedUrl() {
              return this.truncatedUrl;
          }
  
          public void setTime(String time) {
              this.time = time;
          }
  
          public String getTagList() {
              if(tagList == null){
                  return "";
              }
              else {
                  return tagList;
              }
          }
  
          public void setTagList(String tagList) {
              this.tagList = tagList;
          }
  
  
          public String getUrl() {
              return url;
          }
  
          public void setUrl(String url) {
              this.url = url;
          }
  
          public String getNumberOfRecommendations() {
              return numberOfRecommendations;
          }
  
          public void setNumberOfRecommendations(String numberOfRecommendations) {
              this.numberOfRecommendations = numberOfRecommendations;
          }
  
          @Override
          public int compareTo(Object o) {
  
              DateFormat formatter;
              Date date1 = null;
              Date date2 = null;  
              SuggestionDetailBean other = (SuggestionDetailBean) o;
  
              if(this.date == null || other.date == null){
                  return 0;
              }   
              formatter = new SimpleDateFormat(SimpleDateFormatEnum.DATE.getSdfType()+" "+SimpleDateFormatEnum.TIME.getSdfType());
              try {
                  date1 = (Date) formatter.parse(this.date + " " + this.time);
                  date2 = (Date) formatter.parse(other.date + " " + other.time);
              } catch (ParseException e) {
                  System.out.println("Exception thrown in"+this.getClass().getName()+", compareTo method");
                  e.printStackTrace();
              }
              catch(NullPointerException npe){
                  System.out.println("Exception thrown "+npe.getMessage()+" date1 is "+date1+" date2 is "+date2);
              }
  
               return date2.compareTo(date1);
  
          }
  
          @Override
             public int hashCode() {
                  return this.url.hashCode();
              }
  
          @Override
          public boolean equals(Object obj) {
  
              SuggestionDetailBean suggestionDetailBean = (SuggestionDetailBean) obj;
  
              if(StringUtils.isEmpty(this.getTagList())){
                  return this.getUrl().equals(suggestionDetailBean.getUrl());
              }
              else {
                  return (this.getTagList().equals(suggestionDetailBean.getTagList())) &amp;&amp;
                          (this.getUrl().equals(suggestionDetailBean.getUrl()));
              }
  
          }
  
      }
  </code></pre>
  
  <p>Edit : 
  Note : if I convert the hashset to a treeset using : </p>
  
  <pre><code> Set&lt;SuggestionDetailBean&gt; sortedSet = new TreeSet&lt;SuggestionDetailBean&gt;(hashset);
  </code></pre>
  
  <p>Then correct sorting is maintained, as the removal of duplicates is based on the object hashcode and equals methods not the compareto method.</p>