标签:class arraylist element 一个 数据 pre 工具 new out
Collection集合和Collections工具类中addAll() 方法的区别:
Collections工具类中addAll() 方法:
public static <T> boolean addAll(Collection<T> c, T... elements)
往集合中添加一些元素。
Collection集合中的addAll() 方法:
boolean addAll(Collection<? extends E> c);
代码演示:
public class Demo02 {
public static void main(String[] args) {
Set<String> set = new HashSet<>();
Collections.addAll(set,"AA","BB","CC");
System.out.println("set = " + set);
List<String> list = new ArrayList<>();
Collections.addAll(list,"a","b","c");
System.out.println("list = " + list);
//Collection 本身也有一个addAll
list.addAll(set);//将set集合中的所有数据添加到list集合中
System.out.println("list = " + list);
}
}
标签:class arraylist element 一个 数据 pre 工具 new out
原文地址:https://www.cnblogs.com/liqiliang1437/p/13071819.html