我有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"};
。 - Pshemo