title: How to override compareTo (Java)
body: <p>I'm a beginner in programming and I have two classes. First class is:</p>
  
  <pre><code>public class User implements Comparable&lt;User&gt;
  </code></pre>
  
  <p>with field <code>int age</code>, constructor and overrided method of interface Comparable:</p>
  
  <pre><code> @Override
      public int compareTo(User user) {
          return user.age &gt;= age ? -1 : 0;
      }
  </code></pre>
  
  <p>Second class is
  <code>public class SortUser</code> with a method to make a Set collection from a List:</p>
  
  <pre><code>public Set&lt;User&gt; sort(List&lt;User&gt; list) {
          Set&lt;User&gt; result = new TreeSet&lt;&gt;();
          for (User user : list) {
              result.add(user);
          }
          return result;
      }
  </code></pre>
  
  <p>It seems to me that all <code>User</code> objects in a Set should be sorted, but when I made a List with 3 <code>User</code> objects...</p>
  
  <pre><code> User a = new User(1);
   User b = new User(2);
   User c = new User(3);
   List&lt;User&gt; list = new ArrayList&lt;&gt;();
   list.add(c);
   list.add(a);
   list.add(b);
  </code></pre>
  
  <p>(Now the list's order is: <code>312</code>)
  ...and created a <code>Set</code> (<code>TreeSet</code>) from that list:</p>
  
  <pre><code>SortUser sortUser = new SortUser();
  Set&lt;User&gt; set = sortUser.sort(list);
  </code></pre>
  
  <p>At the end I have a <code>set</code> with that order: <code>13</code>, it means that only two objects are in the <code>set</code>. What is going wrong?</p>