欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java合并list方法代碼實(shí)例

 更新時(shí)間:2020年01月03日 08:36:24   作者:哎呦,加油哈  
這篇文章主要介紹了java合并list方法代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

這篇文章主要介紹了java合并list方法代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

List包括List接口以及List接口的所有實(shí)現(xiàn)類。因?yàn)長ist接口實(shí)現(xiàn)了Collection接口,所以List接口擁有Collection接口提供的所有常用方法,又因?yàn)長ist是列表類型,所以List接口還提供了一些適合于自身的常用方法

方法一

  List<Children> reduce = list.stream()
      .map(x -> x.getChildren())
      .reduce(new ArrayList<>(), (all, item) -> {
        all.addAll(item);
        return all;
      });
  System.out.println(reduce);

方法二

List<Children> collect = list.stream()
               .map(Employee::getChildren)
               .flatMap(Collection::stream)
               .distinct().collect(Collectors.toList());
----------------------------
List<Children> childrens1 = new ArrayList<>();
for (long i =0;i<10;i++){
  childrens1.add(new Children(i,"x".concat(i+"")));
}
List<Children> childrens2 = new ArrayList<>();
for (long i =100;i<110;i++){
  childrens2.add(new Children(i,"x".concat(i+"")));
}
Employee mazi = new Employee("麻子", 90, 989.2);
mazi.setChildren(childrens1);
Employee lisi = new Employee("李四", 10, 1000.1);
lisi.setChildren(childrens2);
List<Employee> list = Arrays.asList(mazi,lisi);

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論