looping lists in java
<p>I have a simple java statement along the lines of:</p>

<pre><code>    String[] ykl = yklList.get(0).split(" ");  
</code></pre>

<p>where, yklList is an ArrayList containing sentences which are split into words. The above works fine.</p>

<p>When I now try and loop this:</p>

<pre><code>Loop:1
for (int i=0;i&lt;=4;i++)
{
  String[] ykl = yklList.get(i).split(" ");
}
</code></pre>

<p>It does not seem to work and throws me a compile error. Is the above loop wrong?</p>

<p>I have another for loop after the above:</p>

<pre><code>Loop:2
for (String ykl : yklList)
{
//do something
}
</code></pre>

<p>It throws me a compile error here saying:</p>

<pre><code>cannot find symbol
symbol  : variable ykl
location: class test
for (String ykl : yklList) 
</code></pre>

<p>Presumably Loop 1 went wrong somewhere?</p>

<p><strong>Edit:</strong></p>

<p>The "full" code looks something like this:</p>

<pre><code>for (int i=0;i&lt;=yklList.size()-1;i++)
{
String[] ykl = yklList.get(i).split(" ");  

}       
for (String y : ykl)  
{  
t.add(y);  
}   
</code></pre>

<p>and the error is:</p>

<pre><code>cannot find symbol
symbol  : variable ykl
location: class test
for (String y : ykl) 
</code></pre>
