title: How to correctly initialize a Comparator?
body: <p>I need to write a static method in a class MinTester that computes the "smallest" string 
  from an ArrayList collection using a comparator object:</p>
  
  <pre><code>public static String min(ArrayList&lt;String&gt; list, Comparator&lt;String&gt; comp)
  </code></pre>
  
  <p>I cannot use the Collections class to compute the minimum. </p>
  
  <p>Here is what I have so far.</p>
  
  <pre><code>public class MinTester 
  {
      public static String min(ArrayList&lt;String&gt; list, Comparator&lt;String&gt; comp)
      {
          String shortest = list.get(0);
  
          for(String str : list) {
              if ( comp.compare(str, shortest) &lt; 0) {
                  shortest = str;
              }
          }
          return shortest;
      }
  }
  </code></pre>
  
  <p>I am not getting any errors here from the method, So I try to test it in Main with this. 
  I get this error when trying to pass comp: Variable comp may not have been initialized</p>
  
  <pre><code>public static void main(String[] args)
  {
      // TODO code application logic here
  
      MinTester s = new MinTester();
      Comparator&lt;String&gt; comp;
      ArrayList&lt;String&gt; list = new ArrayList&lt;&gt;();
  
      list.add("a");
      list.add("ab");
      list.add("abc");
      list.add("abcd");
  
      String a = s.min(list,comp);//Error: Variable comp may not have been initialized
  
      System.out.println(a);
  }
  </code></pre>
  
  <p>Heres where I run into my problem.</p>
  
  <p>I try</p>
  
  <pre><code>Comparator&lt;String&gt; comp = new Comparator&lt;&gt;();//Error:Comparator is abstract, cannot be instantiated
  Comparator&lt;String&gt; comp = new MinTester();//Error: MinTester cannot be converted to Comparator&lt;String&gt;
  </code></pre>
  
  <p>Can anyone tell me the proper way to handle this Comparator?  Im not sure if Im just trying to initialize it incorrectly, or if I'm missing something in my MinTester class.</p>