title: Passing an ArrayList to a TreeSet to get the sorted order of elements with removing duplicates
body: <pre class="lang-java prettyprint-override"><code>    List&lt;User&gt; learnersList=null;
      List&lt;User&gt; instructorsList=null;
      List&lt;User&gt; contentCreatorsList=null;
  
      try {
          learnersList=getManagerFactory().getLearningMgmtManager().getAllLearners();
          SortedSet&lt;User&gt; userList =new TreeSet&lt;User&gt; (learnersList);
      } catch (ElearningException e) {
          log.error("Error in gotoinboxpage method in messagemgmt action");
      }   
  </code></pre>
  
  <p>In the above code I want to sort the 'userList' in the natural ordering with unique values. I am planning to use a TreeSet. But I am not getting the list in a sorted way.  Not able to figure out whats going wrong here. The following exception is thrown instead.  Any help?</p>
  
  <p>Unhandled Exception thrown: class java.lang.ClassCastException
  User cannot be cast to java.lang.Comparable</p>
  
  <pre><code>at java.util.TreeMap.compare(TreeMap.java:1188)
      at java.util.TreeMap.put(TreeMap.java:531)
      at java.util.TreeSet.add(TreeSet.java:255)
      at java.util.AbstractCollection.addAll(AbstractCollection.java:334)
      at java.util.TreeSet.addAll(TreeSet.java:312)
      at java.util.TreeSet.&lt;init&gt;(TreeSet.java:160)
  </code></pre>