title: A TreeSet or TreeMap that allow duplicates
body: <p>I need a <code>Collection</code> that sorts the element, but does not removes the duplicates.</p>
  
  <p>I have gone for a <code>TreeSet</code>, since <code>TreeSet</code> actually adds the values to a backed <code>TreeMap</code>: </p>
  
  <pre><code>public boolean add(E e) {
      return m.put(e, PRESENT)==null;
  }
  </code></pre>
  
  <p>And the TreeMap removes the duplicates using the <code>Comparators</code> <code>compare</code> logic</p>
  
  <p>I have written a <code>Comparator</code> that returns 1 instead of 0 in case of equal elements. Hence in the case of equal elements the <code>TreeSet</code> with this <code>Comparator</code> will not overwrite the duplicate and will just sort it.</p>
  
  <p>I have tested it for simple <code>String</code> objects, but I need a Set of Custom objects.</p>
  
  <pre><code>public static void main(String[] args)
  {       
          List&lt;String&gt; strList = Arrays.asList( new String[]{"d","b","c","z","s","b","d","a"} );      
          Set&lt;String&gt; strSet = new TreeSet&lt;String&gt;(new StringComparator());       
          strSet.addAll(strList);     
          System.out.println(strSet); 
  }
  
  class StringComparator implements Comparator&lt;String&gt;
  {
      @Override
      public int compare(String s1, String s2)
      {
          if(s1.compareTo(s2) == 0){
              return 1;
          }
          else{
              return s1.compareTo(s2);
          }
      }
  }
  </code></pre>
  
  <p>Is this approach fine or is there a better way to achieve this?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Actually I am having a ArrayList of the following class:</p>
  
  <pre><code>class Fund 
  {
      String fundCode;
      BigDecimal fundValue;
      .....
  
      public boolean equals(Object obj) {
      // uses fundCode for equality
      }
  }
  </code></pre>
  
  <p>I need all the <code>fundCode</code> with highest <code>fundValue</code></p>