List转成数组,数组转成List

//List转数组
List<String> validators = new ArrayList<>();
validators.add("yuntrust");
validators.add("zhongbang");
String[] validatorsArr = new String[validators.size()];
validatorsArr = validatorsArr.toArray(validatorsArr);

//数组转List
String[] strArr = new String[]{"data","data2"};
List<String> validators = Arrays.asList(strArr);

//使用
validators.toArr
Class ArrayList{

    public <T> T[] toArray(T[] a) {
        if (a.length < size)
            // Make a new array of a's runtime type, but my contents:
            return (T[]) Arrays.copyOf(elementData, size, a.getClass());
        System.arraycopy(elementData, 0, a, 0, size);
        if (a.length > size)
            a[size] = null;
        return a;
    }
}

  

上一篇:more和less命令使用说明


下一篇:一起谈.NET技术,ASP.NET缓存全解析4:应用程序数据缓存