0

I want to know if it possible to handle an array in another array, i never heard of something like that and i'm curious if it is possible, because i'm writing a little programm rigth now and i would need something like this! An example(maybe this can be solved other than using an array in an array): i have two String arrays like this:

public String[] stringArray1 = { "0", "1", "2", "3" }, stringArray2 = { "0", "1", "2", "3" };

now i would need something like this:

public /*type?*/[] allArrays = { stringArray1, stringArray2 };

because i need to access it using an for loop and i dont want to use thousands of if statements to get to the stringArrays(this is just an example in my real programm there are like 100 arrays):

for(int i = 0; i < numberOfArrays/*100*/; i+=2)
test/*a rondom void*/(allArrays[i], allArrays[i+1]);

in my programm there are always two arrays connected that's why i call one with i and one with i+1... so now this is how my test looks like:

public void test(/*type?*/ test1, /*type?*/ test2)
{
//now i need to use test1 & test2 as string to f.e. like this:
if(test1[2].contains("1"))
//do something
}
SyxDuLappen
  • 59
  • 2
  • 8

2 Answers2

2

This is a duplicate. You need an array of arrays.

public String[][] allArrays = { stringArray1, stringArray2 };
Community
  • 1
  • 1
m1o2
  • 1,549
  • 2
  • 17
  • 27
2
String[][] arrays = new String[][] { stringarray1, stringarray2, stringarray3 };
tomtomssi
  • 1,017
  • 5
  • 20
  • 33
SmashCode
  • 741
  • 1
  • 8
  • 14