title: sorting string lengths using comparator
body: <p>While trying to sort an array based on its element string lengths, I am struck with a compile error. I have an set to start with, ,</p>
  
  <pre class="lang-java prettyprint-override"><code>Set&lt;String&gt; arraycat = new HashSet&lt;String&gt;();
  //add contents to arraycat
  String[] array = arraycat.toArray(new String[0]);
  //array looks like this now:
  //array=[cat,cataaaa,cataa,cata,cataaa]
  </code></pre>
  
  <p>I would ideally want to sorted to</p>
  
  <pre class="lang-java prettyprint-override"><code>array=[cat,cata,cataa,cataaa,cataaaa]
  </code></pre>
  
  <p>so I have a comparator of type</p>
  
  <pre><code>class comp implements Comparator {
  
      public int compare(String o1, String o2) {
          if (o1.length() &gt; o2.length()) {
              return 1;
          } else if (o1.length() &lt; o2.length()) {
              return -1;
          } else {
              return 0;
          }
      }
  }
  </code></pre>
  
  <p>and then I call the class by</p>
  
  <pre class="lang-java prettyprint-override"><code>Collections.sort(array, new comp());
  </code></pre>
  
  <p>but then, it throws me two compile errors:</p>
  
  <pre><code>comp is not abstract and does not override abstract method   compare(java.lang.Object,java.lang.Object) in java.util.Comparator
  class comp implements Comparator {
  ^
  testa.java:59: cannot find symbol
  symbol  : method sort(java.lang.String[],comp)
  location: class java.util.Collections
  Collections.sort(array, new comp());
  ^2 errors
  </code></pre>
  
  <p>I would appreciate any clues to solve the problem.</p>