关于数组和List之间相互转换的方法

1.List转换成为数组;返回数组的运行时类型。如果列表能放入指定的数组。否则,将根据指定数组
如果指定的数组的元素比列表的多),那么会将存储列表元素的数组
返回:
包含列表元素的list.add("2");
final int size =  list.size();
String[] arr = (String[])list.toArray(new String[size]);

2.为List
调用Arrays的asList方法.
asList
public static <T> List<T> asList(T... a)返回一个受指定数组。)此方法同 Collection.toArray 一起,充当了基于 
参数:
a - 支持列表的数组的列表视图。
另请参见:
Collection.toArray()

具体用法:
String[] arr = new String[] {"1", "2"};
List list = Arrays.asList(arr);

如果arr为Null,则会报空指针

原文地址:https://www.cnblogs.com/toSeeMyDream/p/5233541.html