码迷,mamicode.com
首页 > 编程语言 > 详细

java map ->语法

时间:2017-06-25 15:29:52      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:stream   chm   stc   asi   add   on()   span   blog   语法   

 List<Person> personList=new ArrayList();
        Person p1=new Person();
        p1.setPersonId(1);
        p1.setPersonName("chm");
        List<Area> areaList1=new ArrayList<>();
        Area a1=new Area();
        a1.setAreaId(1);
        a1.setAreaName("海淀");
        a1.setCityId(1);
        areaList1.add(a1);
        Area a2=new Area();
        a2.setAreaId(2);
        a2.setAreaName("丰台");
        a2.setCityId(1);
        areaList1.add(a2);
        Area a3=new Area();
        a3.setAreaId(11);
        a3.setAreaName("崇明");
        a3.setCityId(2);
        areaList1.add(a3);
        p1.setAreaList(areaList1);
        personList.add(p1);

        Person p2=new Person();
        p2.setPersonId(2);
        p2.setPersonName("wt");
        List<Area> areaList2=new ArrayList<>();
        Area a11=new Area();
        a11.setAreaId(21);
        a11.setAreaName("临颍");
        a11.setCityId(3);
        areaList2.add(a11);
        Area a12=new Area();
        a12.setAreaId(22);
        a12.setAreaName("郾城");
        a12.setCityId(3);
        areaList2.add(a12);
        Area a13=new Area();
        a13.setAreaId(12);
        a13.setAreaName("浦东");
        a13.setCityId(2);
        areaList2.add(a13);
        p2.setAreaList(areaList2);
        personList.add(p2);
        List<Integer> cityIdList=new ArrayList<>();
        for(Person person:personList){
            for(Area area:person.getAreaList()){
                if(!cityIdList.contains(area.getCityId())){
                    cityIdList.add(area.getCityId());
                }
            }
        }

List<List<Integer>> myList= personList.stream().map(i->i.getAreaList().stream().map(area->area.getCityId()).collect(Collectors.toList())).collect(Collectors.toList());

        Map<Integer, List<Person>> basicMap = personList.stream().collect(Collectors.groupingBy(Person::getPersonId));
        List<Person>  personListCurrent=basicMap.get(2);

 

java map ->语法

标签:stream   chm   stc   asi   add   on()   span   blog   语法   

原文地址:http://www.cnblogs.com/caohuimingfa/p/7076816.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!