数组转换成List

可以用Collections.addAll(list,a)或者list = Arrays.asList(a)方法将一个数组转换成List

public class Test {
    public static void main(String[] args) {
//        int[] a = {1,2,3};  //基本类型的数组不行,会报错
        Integer[] a = new Integer[]{1,2,3};
        List<Integer> list = new ArrayList<>();

//        Collections.addAll(list,a);
        list = Arrays.asList(a);

        System.out.println(list);
    }
}

输出

[1, 2, 3]
全部评论

相关推荐

Aurora23:属于挂一半,暂时进池子了,隔一段时间没有其他组捞的话就彻底结束了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务