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);
时间: 2024-11-05 22:05:46