I have a simple java statement along the lines of:
String[] ykl = yklList.get(0).split(" ");
where, yklList is an ArrayList containing sentences which are split into words. The above works fine.
When I now try and loop this:
Loop:1
for (int i=0;i<=4;i++)
{
String[] ykl = yklList.get(i).split(" ");
}
It does not seem to work and throws me a compile error. Is the above loop wrong?
I have another for loop after the above:
Loop:2
for (String ykl : yklList)
{
//do something
}
It throws me a compile error here saying:
cannot find symbol
symbol : variable ykl
location: class test
for (String ykl : yklList)
Presumably Loop 1 went wrong somewhere?
Edit:
The “full” code looks something like this:
for (int i=0;i<=yklList.size()-1;i++)
{
String[] ykl = yklList.get(i).split(" ");
}
for (String y : ykl)
{
t.add(y);
}
and the error is:
cannot find symbol
symbol : variable ykl
location: class test
for (String y : ykl)
Regarding to your update:
You define
yklin the first loop. So the variable is not in the scope of the second loop. Your code have to look like this:By the way: If you would use an IDE like Eclipse you would see those errors in the editor!