title: How to sort an ArrayList in Java
body: <p>I have a class named Fruit. I am creating a list of this class and adding each fruit in the list. I want to sort this list based on the order of fruit name.</p>
  
  <pre><code>public class Fruit{
  
      private String fruitName;
      private String fruitDesc;
      private int quantity;
  
      public String getFruitName() {
          return fruitName;
      }
      public void setFruitName(String fruitName) {
          this.fruitName = fruitName;
      }
      public String getFruitDesc() {
          return fruitDesc;
      }
      public void setFruitDesc(String fruitDesc) {
          this.fruitDesc = fruitDesc;
      }
      public int getQuantity() {
          return quantity;
      }
      public void setQuantity(int quantity) {
          this.quantity = quantity;
      }
  }
  </code></pre>
  
  <p>and I am creating its list using for loop</p>
  
  <pre><code>List&lt;Fruit&gt;  fruits= new ArrayList&lt;Fruit&gt;();
  
  Fruit fruit;
  for(int i=0;i&lt;100;i++)
  {
     fruit = new fruit();
     fruit.setname(...);
     fruits.add(fruit);
  }
  </code></pre>
  
  <p>and I need to sort this arrayList using the fruit name of each object in the list</p>
  
  <p>how??</p>