title: How do I sort an ArrayList of strings by alphabetical order?
body: <p>I'm trying to create a program that can sort the contents of an ArrayList alphabetically. Right now I have three classes in my program...</p>
  
  <p>Dog</p>
  
  <pre><code>public class Dog {
      private String name;
  
      public Dog(){
  
      }
  
      public void setName(String name){
          this.name = name;
      }
  
      public String getName(){
          return this.name;
      }
  }
  </code></pre>
  
  <p>DogList (which contains the ArrayList of type Dog)</p>
  
  <pre><code>import java.util.ArrayList;
  
  public class DogList {
  
      private ArrayList&lt;Dog&gt; dogList;
  
      public DogList(){
          DogList = new ArrayList&lt;&gt;();
      }
  
      public void setSize(int DogSize){
          for(int x = 0; x &lt;= DogSize; x++){
              DogList.add(new Dog());
          }
      }
  
      public ArrayList&lt;Dog&gt; getList(){
          return dogList;
      }
  }
  </code></pre>
  
  <p>and the last class, DogSorter, which is trying to access DogList ArrayList and then trying to sort the contents of that ArrayList in alphabetical order.</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Collections;
  import java.util.Comparator;
  import java.util.List;
  
  
  public class DogSorter {
      private DogList list = new DogList();
  
      public void sortDogs{
          Collections.sort(list);
      }
  
      for(i = 0; i &lt; list.length(); i++) {
          System.out.println(list.getList().get(i).getName();
      }
  }
  </code></pre>
  
  <p>I apologize for the long post. My question is simply: How do I sort the contents of the ArrayList accurately? I keep getting an error saying that I'm trying to compare the wrong types with my "Collections.sort" line. If anyone can help out, please let me know. Thank you.</p>
  
  <p>edit: To be clear, I'm trying to sort them alphabetically by the string stored in getName() for each object</p>