title: How to sort Array list integer type
body: <p>I have an object class Product as shown below</p>
  
  <pre><code>public class Product {
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      String name;
  
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public String getImage() {
          return image;
      }
  
      public void setImage(String image) {
          this.image = image;
      }
  
      public int getPrice() {
          return price;
      }
  
      public void setPrice(int price) {
          this.price = price;
      }
  
      int price;
      String id;
      String image;
  }
  </code></pre>
  
  <p>I want to sort the products with the basis of price.
  my array is</p>
  
  <pre><code> List&lt;Product&gt; products=new ArrayList&lt;&gt;();
  
   for(int i=0;i&lt;ja3.length();i++){
       JSONObject jsonObject=ja3.getJSONObject(i);
       Product product=new Product();
       product.setId(jsonObject.getString("product_id"));
       product.setImage("http://ezybzy.com/images/"+jsonObject.getString("product_id")+"/1.jpg");
       product.setPrice(jsonObject.getInt("product_SP"));
       product.setName(jsonObject.getString("product_name"));
       products.add(product)
   }
  </code></pre>
  
  <p>I did </p>
  
  <pre><code>Collections.sort(products, new Comparator&lt;Product&gt;() {
      @Override
      public int compare(Product lhs, Product rhs) {
          return lhs.getPrice().compareTo(rhs.getPrice());
      }
  })
  </code></pre>
  
  <p>But the issue is that <code>.compareTo(rhs.getPrice()</code> part is in error.It cant use <code>compareTo</code> method.I want my arrayList sorted in the basis of the price of the product.The price is the integer value.But when I Changed it to String type I got <code>CompareTo</code> but its still unsorted because of the String type.Please Help me</p>