两个list合并成一个list的操作 您所在的位置:网站首页 两个list合并成一个list 两个list合并成一个list的操作

两个list合并成一个list的操作

#两个list合并成一个list的操作| 来源: 网络整理| 查看: 265

addAll  添加另一集合里面的元素

add 添加整个集合包括 []

 

 

Stream 操作 合并两个lis  出自http://www.it1352.com/963663.html

 

 

1 public class Test { 2 public static void main(String[] args) { 3 4 List destList = Collections.synchronizedList(new ArrayList(Arrays.asList("foo"))); 5 6 List newList = Arrays.asList("0", "1", "2", "3", "4", "5"); 7 8 newList.stream().sequential().collect(Collectors.toCollection(() -> destList)); 9 10 //newList + destList 的内容 11 //结果 [foo, 0, 1, 2, 3, 4, 5] 12 System.out.println(destList); 13 14 System.out.println("=========================================="); 15 16 List listOne = new ArrayList(); 17 listOne.add("333"); 18 listOne.add("666"); 19 listOne.add("999"); 20 21 List listTwo = new ArrayList(); 22 listTwo.add("A"); 23 listTwo.add("B"); 24 listTwo.add("C"); 25 26 //addAll 添加另一集合里面的元素 27 //结果[333, 666, 999, A, B, C] 28 listOne.addAll(listTwo); 29 System.out.println(listOne); 30 31 32 //add 添加整个集合包括 [] 33 //结果 [A, B, C, [333, 666, 999, A, B, C]] 34 listTwo.add(listOne.toString()); 35 System.out.println(listTwo); 36 37 } 38 39 }

 

 

 

 

 



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有