Android转换列表<string []>到String [] </string []>

时间:2011-04-09 06:54:34

标签: android

Android如何将List<String[]>转换为String[] .....

2 个答案:

答案 0 :(得分:9)

    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()]);
    }

使用示例:

    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());
    }

答案 1 :(得分:1)

如果您尝试转换List&lt;串GT;对于String [],您可以使用List.toArray()