Java List与数组之间的转换
1 数组转换为List
调用Arrays类的静态方法asList。
public static <T> List<T> asList(T... a)
Collection.toArray(). The returned list is serializable and implements RandomAccess.This method also provides a convenient way to create a fixed-size list initialized to contain several elements:
List<String> stooges = Arrays.asList("Larry", "Moe", "Curly"); a - the array by which the list will be backedReturns:a list view of the specified arrayList<String> list = new ArrayList<String>();list.add("str1");list.add("str2");int size = list.size();String[] arr = (String[])list.toArray(new String[size]);//使用了第二种接口,返回值和参数均为结果