简体   繁体   English

数组内部的数组android

[英]array inside array android

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. 但我想要的是创建一个两个数组..一个用于数组类,然后另一个用于我将用于使用for循环的所选类的信息。 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. 好吧,如果它是可行的,我的工作将耗费更少的时间..谢谢。

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];

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. 然后你可以像常规数组一样使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM