title: How to sort List of User-defined type in Java?
body: <p>I'm currently learning how to work with Lists in Java. I've come across sorting Strings in a List by using Collections.sort() method and that works fine. However when I create a user-defined datatype, it doesn't sort and gives an error - <br/><br/>
  <strong>"no suitable method found for sort(List)
      method Collections.sort(List,Comparator) is not applicable
        (cannot instantiate from arguments because actual and formal argument lists differ in length)
      method Collections.sort(List) is not applicable
        (inferred type does not conform to declared bound(s)
          inferred: Child
          bound(s): Comparable)
    where T#1,T#2 are type-variables:
      T#1 extends Object declared in method sort(List,Comparator)
      T#2 extends Comparable declared in method sort(List)"</strong><br/><br/>
  How can I sort the elements for a user-defined type? </p>
  
  <p>Here is the code - <br/></p>
  
  <h2>CODE - <br/></h2>
  
  <pre><code>package works;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.List;
  import java.util.Collections;
  
  class Child 
  {
  private String name;
  public Child(String name)
  {
      this.name=name;
  }
  @Override
  public String toString()
  {
      return name;
  }
  }
  class LOL
  {
  void Meth()
  {
      Child s1 = new Child("Hi");
      Child s2 = new Child("Bye");
      Child s3 = new Child("And");
      List&lt;Child&gt; f1 = Arrays.asList(s1,s2,s3);
      System.out.println(f1);
      System.out.println();
      Collections.sort(f1);  // This line is the erroneous line.
  }
  }
  public class SortColl
  {
  public static void main(String X[])
  {
      LOL l = new LOL();
      l.Meth();
  
  }
  }
  </code></pre>