Addressing an Array which doesn't exist until a loop runs?

HI,

I'm trying to address an array which is created by a loop. But as its name doesn't yet exist I can't compile it.

My code

{

BufferedReader into=new BufferedReader(new FileReader(args[0]));

while ((thisLine = into.readLine()) !=null )

{

fileloc = thisLine.split (",");

filelist.add(fileloc[1]);

ArrayList<String> arrayname =new ArrayList<String>();

String arraynamer = ("array"+fileloc[0]) ;

FileReaderfile =new FileReader(fileloc[1]);

BufferedReader in=new BufferedReader(file);

StreamTokenizer st=new StreamTokenizer(in);

ArrayList<String> temparray =new ArrayList<String>();

while ((tokval = st.nextToken()) != StreamTokenizer.TT_EOF)

{

switch (tokval)

{

case StreamTokenizer.TT_WORD:

temparray.add(st.sval);

break;

case StreamTokenizer.TT_NUMBER:

String number2 = Double.toString(st.nval);

temparray.add(number2);

break;

default:

break;

}

}

ArrayList $arraynamer = (ArrayList)temparray.clone();

}

}

The file its assessing is laid out like

0, c:\filepath

1, c:\otherfilepath

For each of the lines isted in the file it should creates a new array called whatever is before the "," array0, array1 etc

Now I can access the data using $arraynamer, providing I'm in the loop, but I can't access array0 at all because it doesn't exist until the program runs.

So for example if I add in

System.out.println("HI:"+array0.get(1);

I get

arraypopulator.java:78: cannot find symbol

symbol : variable $array0

location: class arraypopulator

System.out.println("TRIAL1:"+$array0.get(1));

^

1 error

I have tried with/without the $.

[2694 byte] By [wuciwuga] at [2007-11-27 4:05:47]
# 1
Java does not support magical creation of variables. Use a [url= http://java.sun.com/j2se/1.5/docs/api/java/util/Map.html]map[/url].
mlka at 2007-7-12 9:10:48 > top of Java-index,Java Essentials,Java Programming...
# 2
Its hard to figure what you are trying to achieve.If you want to access all the arrays then define then before the loop and initialize them in the loop.
--stallion--a at 2007-7-12 9:10:48 > top of Java-index,Java Essentials,Java Programming...
# 3

HI,

I can't pre-define the arrays because I don't know how many there will be.

In short, My loops create arrays. I want to be able to address the arrays but I can't complie my code because the arrays don't exist.

I can't find any good examples of map, so i'm not sure what it does. But if I can use it to reference yet to be created arrays it'll do what i need.

TIA

G

wuciwuga at 2007-7-12 9:10:48 > top of Java-index,Java Essentials,Java Programming...
# 4
> I can't pre-define the arrays because I don't know how many there will be.You are already using a variable length array (ArrayList).
mlka at 2007-7-12 9:10:48 > top of Java-index,Java Essentials,Java Programming...
# 5
Sorry, not how many values there will be in the array. But how many array's there will be.For every line in my file I want a new array to be created.
wuciwuga at 2007-7-12 9:10:48 > top of Java-index,Java Essentials,Java Programming...
# 6

> Sorry, not how many values there will be in the

> array. But how many array's there will be.

>

> For every line in my file I want a new array to be

> created.

These arrays will be nameless- you will only know them from their index in the ArrayList. Something like

ArrayList<int[]> t = new ArrayList<int[]>();

t.add(new int[4]);

Message was edited by:

snic.snac

snic.snaca at 2007-7-12 9:10:48 > top of Java-index,Java Essentials,Java Programming...