Simple question with arrays
807598Aug 13 2006 — edited Aug 13 2006Im a couple days new in java, Ive been searching for an answer for hours and havent found a solution.
This is the mistake it shows (when trying to use any element of the array):
array required, but java.util.ArrayList <java.lang.String> found
The array is:
public static ArrayList<String> numList = new ArrayList<String>();
Im filling it this way: (so that it contains each word of a file in separate)
BufferedReader br = new BufferedReader(new FileReader("Archivo.txt"));
try
{
while(true)
{
String aLine = br.readLine();
if(aLine == null) throw new EOFException("Le?do todo el archivo.");
if(!aLine.equals(""))
{
StringTokenizer st = new StringTokenizer(aLine);
while(st.hasMoreTokens())
{
numList.add(st.nextToken());
}
}
}
}catch(EOFException e)
{
The problem comes when I try to use the elements of the array (in specific when trying to convert each element of the array to int, so that i can do math operations with them).
for example:
for (a=0; w>a; a++)
{
int x = Integer.parseInt(numList[a])
}
Can anyone help me with this? (where is the mistake and how to convert from string array elements to int)
Thank you // Muchas Gracias