Variable array names...i think

I have a list of arrays which need filling and i have created a for lop that will run the necessary commands to fill the arrays...

how do i put an array name into the 'for' loop that will change each time...

ie.

for(int x = 0; x < 3; x++)

{

array ?x? [index] = tempVariable;

}

Message was edited by: Reashlin

reashlin

[496 byte] By [reashlina] at [2007-11-26 18:05:40]
# 1

You don't.

An array's index can be variable, but a variable's name cannot. If you really need "named" arrays, put the arrays into a map.

Map<String, int[]> arrayMap = new HashMap<String, int[]>();

int[] array1 = new int[10];

arrayMap.put("array1", array1);

array1[0] = 123;

http://java.sun.com/docs/books/tutorial/collections/

Or, if accessing the array by an index is enough, then just use an array of arrays.

int [][] arrays = new int[5][10];

array[0][0] = 1;

... etc. ..

jverda at 2007-7-9 5:36:20 > top of Java-index,Java Essentials,New To Java...
# 2
Assumming by "list" you mean an array of other arrays, you access an element of a specific array like this:multiDimensionalArray[x][y]
JimmyMa at 2007-7-9 5:36:20 > top of Java-index,Java Essentials,New To Java...
# 3
You can use two dimensional arrays.
qUesT_foR_knOwLeDgea at 2007-7-9 5:36:20 > top of Java-index,Java Essentials,New To Java...
# 4
The first index in [ ] [ ] will represent a different array and the second will represent each array specifically.
qUesT_foR_knOwLeDgea at 2007-7-9 5:36:20 > top of Java-index,Java Essentials,New To Java...
# 5
excellent help guys...i had heard of multi dimensional arrays before but could not work out how to do them...this will help me immensly...
reashlina at 2007-7-9 5:36:20 > top of Java-index,Java Essentials,New To Java...
# 6

> i had heard of multi dimensional arrays before

>but could not work out how to do them.

There you go

http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla:en-US:official&hs=1ox&sa=X&oi=spell&resnum=0&ct=result&cd=1&q=java+multidimensional+arrays&spell=1

qUesT_foR_knOwLeDgea at 2007-7-9 5:36:20 > top of Java-index,Java Essentials,New To Java...