Reputation: 805
I dont know how to do this. But what i want is to create a two array.. one for the array class then the other is for the information that i will use for the selected class using for loop. I prefer for loop that for each loop.. ^_^.. My question is. Is it posible to create an array in which it will store an array too? for example:
private final Class<?>[] cls = {class1,class2,class3};
private final String[] myFirstArray = {array1[],array2[],array[]3};
private final String selectedarray[];
for(int i=0;i<cls.lenght();i++){
if(myArrayClassParameter == cls[i]){
selectedArray[] = myFirstArray[i];
}
}
Like that?
Well If it is posible my work will be less time consuming.. thanks.
Upvotes: 3
Views: 7962
Reputation: 8049
Yes. These are called multidimensional arrays. Try them out and mess around with them. You'll learn better that way.
You must declare them like this:
Type[] smallerArray1;
Type[] smallerArray2;
Type[] smallerArray3;
Type[][] biggerArray = new Type[][]{smallerArray1, smallerArray2, smallerArray3};
Then you can use them like regular arrays.
Upvotes: 2
Reputation: 727137
Absolutely - you can create arrays of arrays, or even arrays of arrays of arrays, and so on. All you need is to add more pairs of square brackets []
.
private final String[][] firstArray = new String[][] {
new String[] {"quick", "brown", "fox"}
, new String[] {"jumps", "over", "the"}
, new String[] {"lazy", "dog", "!"}
};
String[] selectedArray = firstArray[1];
Upvotes: 6