dynamic variable name generation

Hi people,

Is there any way of generating variable names dynamically in java in a loop? i.e.

for(int i = 0; i<arrayLength; i++) {

ArrayX.add(position, object)

X++

}

Where X is 0,1,2...etc. so i would have Array1 with something in it, Array2 with something in it, Array3 and so on.

This is just a simple example but I've basically got an initial array of URL objects and then I want to call my getURL method on each link in my inital array and store the links associated to each initial URL in a different Array.

Hope it makes sense, and i hope someone can help!

Thanks in advance.>

[649 byte] By [faraz4evera] at [2007-10-2 10:49:43]
# 1

Your example code is not clear to me (what is "position?"), and your description using URLs doesn't seem to need what you are asking for. I would be careful about using arrays - people sometimes use arrays when classes should be used.

Anyway, I think you can get close to what you want by using a HashMap. You can use Strings as keys and the Strings would be "array01" "array02" etc.

atmguya at 2007-7-13 3:07:11 > top of Java-index,Developer Tools,Java Compiler...
# 2
position is just where in the array the item is stored, i.e. Array[0], Array[1] etc. A bit unsure now since you say I could use a HashMap. I shall have a look into it to see if that would be more appropriate.Thanks for the help anyway.
faraz4evera at 2007-7-13 3:07:11 > top of Java-index,Developer Tools,Java Compiler...