title: Why the following code gives an error
body: <p>The code below gives me a compiling error. It says I should have initialised <code>v</code> somewhere before using it in the second loop while in the first loop everything seems fine. I thought maybe it will implicitly initialised to 0. Appreciate any feedback on this. Also, What is the best practice in such cases. </p>
  
  <pre><code>public static void main(String[] args) {
      ArrayList&lt;Integer&gt; list=new ArrayList&lt;Integer&gt;();
      ArrayList&lt;Integer&gt;[] list2=(ArrayList&lt;Integer&gt;[])new ArrayList[10];
     for(int v:list)
          System.out.println(v);
  
     for(int v:list2[v])
          System.out.println(v);
  }
  </code></pre>