title: Sort elements from item class
body: <p>I have an <code>Item</code> class which has <code>id</code>, <code>count</code>, <code>name</code> as instance variables. I want to sort the items based on count. Please tell me how to go about it. Any method which I can define in my item class to sort the items?</p>
  <p>Below is my item class</p>
  <pre class="lang-java prettyprint-override"><code>public class Item {
  
      private String id;
      private String count;
      private String name;
  
      Item() {
      }
  
      public String getcount() {
          return this.count;
      }
  
      public Item(String name) {
          this.name = name;
          this.id = &quot;&quot;;
  
      }
  
      public Item(String id, String name) {
          this.name = name;
          this.id = id;
  
      }
      
      public Item(String id, String name,String count) {
          this.name = name;
          this.id = id;
          this.count=count;
      }
  
      public String getItemName() {
          return this.name;
      }
  
      public String getItemId() {
          return this.id;
      }
  
      public void createItem(String id, String name) {
          this.name = name;
          this.id = id;
      }
  
      public Item returnItems(ItemList itemset) {
          Item item = null;
  
          return item;
      }
  }
  </code></pre>
  <p>And I have an <code>ItemList</code> class as well, which holds items.</p>
  <pre class="lang-java prettyprint-override"><code>public class ItemList implements Iterable&lt;Item&gt; {
  
      private List&lt;Item&gt; hold = new ArrayList&lt;Item&gt;();
  
      ItemList(Item item) {
  
          // hold = new ArrayList&lt;Item&gt;();
          this.hold.add(item);
      }
  
      ItemList() {
          //throw new UnsupportedOperationException(&quot;Not yet implemented&quot;);
      }
  
      public List&lt;Item&gt; getItemList() {
          return this.hold;
  
      }
  
      public void addItems(Item item) {
          //hold = new ArrayList&lt;Item&gt;();
          this.hold.add(item);
      }
  
      @Override
      public Iterator&lt;Item&gt; iterator() {
          Iterator&lt;Item&gt; item = hold.iterator();
          return item;
      }
  }
  </code></pre>