addAll 添加另一集合里面的元素
add 添加整个集合包括 []
Stream 操作 合并两个lis 出自http://www.it1352.com/963663.html
public class Test {
public static void main(String[] args) { List<String> destList = Collections.synchronizedList(new ArrayList<>(Arrays.asList("foo"))); List<String> newList = Arrays.asList("0", "1", "2", "3", "4", "5"); newList.stream().sequential().collect(Collectors.toCollection(() -> destList)); //newList + destList 的内容
//结果 [foo, 0, 1, 2, 3, 4, 5]
System.out.println(destList); System.out.println("=========================================="); List<String> listOne = new ArrayList<String>();
listOne.add("333");
listOne.add("666");
listOne.add("999"); List<String> listTwo = new ArrayList<String>();
listTwo.add("A");
listTwo.add("B");
listTwo.add("C"); //addAll 添加另一集合里面的元素
//结果[333, 666, 999, A, B, C]
listOne.addAll(listTwo);
System.out.println(listOne); //add 添加整个集合包括 []
//结果 [A, B, C, [333, 666, 999, A, B, C]]
listTwo.add(listOne.toString());
System.out.println(listTwo); } }