title: Sort a list that contains a custom class
body: <p>so I'm currently doing an exercise for college that has several optional parts (because we havn't done this in class yet), one of them being to use lists instead of arrays (so it'd be variable size) and another one printing the list sorted by points (I'll get to that now)</p>
  <p>So, I have the Player.java class which looks like this.</p>
  <pre><code>public class Player {
      String name;
      String password;
      int chips;
      int points;
  
      public Player(String n, String pw, int c, int p) {
          name = n;
          password = pw;
          chips = c;
          points = p;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String n) {
          name = n;
      }
  
      public void setPW(String pw) {
          password = pw;
      }
  
      public String getPW() {
          return password;
      }
  
      public void setChips(int c) {
          chips = c;
      }
  
      public int getChips() {
          return chips;
      }
  
      public void setPoints(int p) {
          points = p;
      }
  
      public int getPoints() {
          return points;
      }
  }
  </code></pre>
  <p>Pretty simple, then I'm creating a List with this (in another class):</p>
  <pre><code>List&lt;Player&gt; lplayer = new ArrayList&lt;Player&gt;(); 
  </code></pre>
  <p>Adding players with this:</p>
  <pre><code>lplayer.add(new Player(n,pw,c,p))`
  </code></pre>
  <p>And finally reading their stats with this:</p>
  <pre><code>public int search_Player (String n) {
      String name;
      int i = 0;
      boolean found = false;
      while ((i &lt;= tp) &amp;&amp; (!found)) {
          name = lplayer.get(i).getName();
          if (name.equals(n)) {
              found = true;
          }
          i++;
      }
      return (found == true) ? i-1 : -1;
  }
  public Player show_Player (int i) {
      return lplayer.get(i);
  }
  public void list_Players() {
      Collections.sort(lplayer);
      int i2;
      if (tp &gt; 0) { // variable which contains number of total players
          for (int i = 0;i&lt;tp;i++) {
              i2 = i+1;
              System.out.println (&quot;\n&quot;+i2+&quot;. &quot;+lplayer.get(i).getName()+&quot; [CHIPS: &quot;+lplayer.get(i).getChips()+&quot; - POINTS: &quot;+lplayer.get(i).getPoints()+&quot;]&quot;);
          }
      }
      else {
          System.out.println (&quot;There are no players yet.&quot;);
      }
  }
  </code></pre>
  <p>So that's basically all the code. As you can see the I already have a list_Players function but that just prints it in the order it was added. I need a way to print in sorted by the points each player has (so basically a ranking).</p>
  <p>As you can see I'm pretty new to java so please try not to come up with a very complicated way of doing it.</p>
  <p>I've already searched for it and found things like Collections.sort(list) but I guess that's not what I need right here.</p>
  <p>Thank you!</p>