作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有 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);
最佳答案
很简单。检查这个link有关创建、初始化和访问数组的更多信息。
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"};
String[][] allArray = {
array1,
array2,
array3,
array4
};
关于java - 如何将字符串数组放入字符串数组的数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27432520/
我是一名优秀的程序员,十分优秀!