Android Convert List<String[]> to String[]
Android How to Convert List&开发者_如何学Clt;String[]>
to String[]
.....
static String[] convert(List<String[]> from) {
ArrayList<String> list = new ArrayList<String>();
for (String[] strings : from) {
Collections.addAll(list, strings);
}
return list.toArray(new String[list.size()]);
}
Example use:
public static void main(String[] args) {
List<String[]> list = new ArrayList<String[]>();
list.add(new String[] { "one", "two" });
list.add(new String[] { "three", "four", "five" });
list.add(new String[] { "six", "seven" });
String[] converted = convert(list);
System.out.print(converted.toString());
}
If you are trying to convert a List< String> to a String[ ], you can use List.toArray()
精彩评论