title: Finding the string has max length in a list with syntax "for(Type varName:list)"
body: <p>i already wrote codes to examine a string has max length in a list like this:</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Arrays;
  
  public class MaxLength {
      public static void main (String [] args){
          ArrayList&lt;String&gt; mylist= new ArrayList &lt;&gt;(Arrays.asList("abc","Hello","young","12345"));
          System.out.println(max(mylist));
      }
      public static String max(ArrayList &lt;String&gt; list){
          String a= "";
          for(int i=0;i&lt;list.size();i=i+1){
              if(list.get(i).length()&gt;=a.length()){
                  a=list.get(i);
                  for(String si:list){System.out.println(si);}
              }
          }
  
          return a;} 
  }
  </code></pre>
  
  <p>Now I want to use <code>for(Type varName:list)</code> in order to iterate
  on the elements ignoring the index and rewrite the max function.How should it be written to compare elements without using index? Thanks in advance.</p>