开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜