您可以使用
将ArrayList<String>
转换为String[]
ArrayList<String> stringList = new ArrayList<String>();
stringList.add("one");
stringList.add("two");
String[] strings1 = Arrays.copyOf(stringList.toArray(), stringList.toArray().length, String[].class);
但是如何将ArrayList<ArrayList<String>>
转换为String[][]
?
ArrayList<ArrayList<String>> listOfStringLists = new ArrayList<ArrayList<String>>();
答案 0 :(得分:0)
String[][] strings2 = convertStringArrayList(listOfStringLists);
将ArrayList<ArrayList<String>>
转换为String[][]
方法:
private String[][] convertStringArrayList( ArrayList<ArrayList<String>> listOfStringLists ) {
String[][] stringGroups = new String[listOfStringLists.size()][];
for ( int i=0; i< listOfStringLists.size(); i++ ) {
ArrayList<String> stringArray = listOfStringLists.get(i);
String[] stringsChildren = Arrays.copyOf(stringArray.toArray(), stringArray.toArray().length, String[].class);
stringGroups[i] = stringsChildren;
}
return stringGroups;
}