title: How to use the Comparator interface
body: <p>I'm new to java, and I'm not really getting how to use the comparator interface.
  I have an <code>ArrayList</code> of <code>Item</code>s in an <code>Inventory</code> class and an <code>Item</code> class.
  In the <code>Item</code> class I wrote:</p>
  
  <pre><code>public class Item implements Comparator&lt;Item&gt; {
      //stuff
      ...
      @Override
      public int compare(Item a, Item b) {
          if (a.getID().compareToIgnoreCase(b.getID())&gt;0)
              return 1;
          else if (a.getID().compareToIgnoreCase(b.getID())&lt;0)
              return -1;
          else
              return 0;
      }
  }
  </code></pre>
  
  <p>The getID() method just gives the id, which I have to use to alphabetize the items.
  I'm not sure if this is right, it made me put the <code>@Override</code> annotation, I'm not sure why. Also I wrote an interface that just says:</p>
  
  <pre><code> public interface Comparator&lt;Item&gt;
  {
      int compare(Item a, Item b);
  }
  </code></pre>
  
  <p>I'm not sure about that bit. Also how do I implement this method to sort the arraylist created in the inventory class?</p>
  
  <p>Thanks, if my question doesn't make sense or needs clarification just let me know.</p>