提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将集合<;String>转换为String[]数组
/**来 自 n o w j a v a . c o m**/ //package com.nowjava; import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { public static void main(String[] argv) { Collection c = java.util.Arrays.asList("asdf", "nowjava.com"); System.out.println(java.util.Arrays.toString(convert(c))); } public static String[] convert(Collection<String> c) { if (c == null) return null; /** 来自 N o w J a v a . c o m - 时 代 Java**/ String[] r = new String[c.size()]; int i = 0; for (String s : c) { r[i] = s; i++; } return r; } public static List<String> convert(String[] c) { List<String> l = new ArrayList<String>();