转自:
java中Collections.addAll方法具有什么功能呢?
下文笔者讲述Collections.addAll方法的功能简介说明,如下所示:
Collections.addAll方法简介
Collections.addAll方法 是java.util包下面Collections类中的方法 Collections.addAll方法的功能: 向一个list中添加数据 其可实现的效果为: 一次添加多个元素
例
ArrayList<String> list = new ArrayList<>();
Collections.addAll(list, "maomao", "java265", "xiaoxiao", "other", "秦铭铭");
String[] arr = {"maomao", "java265", "xiaoxiao", "other", "秦铭铭"};
ArrayList<String> list = new ArrayList<>();
Collections.addAll(list, arr);
String[] arr = {"maomao", "java265", "xiaoxiao", "other", "秦铭铭"};
ArrayList<String> list = new ArrayList<>();
list.addAll(Arrays.asList(arr));
// 或
String[] arr = {"maomao", "java265", "xiaoxiao", "other", "秦铭铭"};
ArrayList<String> list = new ArrayList<>(Arrays.asList(arr));