【发布时间】:2014-12-11 21:17:01
【问题描述】:
我有 4 个这样的字符串数组:
String[] array1 = new String{"there", "there2", "there3", "there4"};
String[] array2 = new String{"here","here2","here3"};
String[] array3 = new String{"hi","hi2"};
String[] array4 = new String{"blah","blah2","blah3"};
我想将它们放入一个数组中,如下所示:
Array myArray = [{"there", "there2", "there3", "there4"},
{"here","here2","here3"},{"hi","hi2"},
{"blah","blah2","blah3"}];
然后就可以像这样访问其中的元素了:
myArray[0][1] would equal "there2"
myArray[1][2] would equal "here3"
希望这是有道理的,我该怎么做?
我尝试过制作这样的 ArrayList,然后添加它们,但它似乎不起作用
ArrayList<String[]> myArrayList = new ArrayList<String[]>();
myArrayList.add(myArray);
【问题讨论】:
-
这很奇怪......你已经知道如何访问你想要的数组,但你还没有尝试过这样定义它?
-
看来你打错了。
String[] array1 = new String{"there", "there2", "there3", "there4"};不会创建数组。要么删除new String[],只留下String[] array1 = {your, elemements};,要么通过添加[](如new String[]{"there", "there2", "there3", "there4"};)显式添加数组类型。