List personList=newArrayList();
Person p1=newPerson();
p1.setPersonId(1);
p1.setPersonName(“chm”);
List areaList1=new ArrayList<>();
Area a1=newArea();
a1.setAreaId(1);
a1.setAreaName(“海淀”);
a1.setCityId(1);
areaList1.add(a1);
Area a2=newArea();
a2.setAreaId(2);
a2.setAreaName(“丰台”);
a2.setCityId(1);
areaList1.add(a2);
Area a3=newArea();
a3.setAreaId(11);
a3.setAreaName(“崇明”);
a3.setCityId(2);
areaList1.add(a3);
p1.setAreaList(areaList1);
personList.add(p1);
Person p2=newPerson();
p2.setPersonId(2);
p2.setPersonName(“wt”);
List areaList2=new ArrayList<>();
Area a11=newArea();
a11.setAreaId(21);
a11.setAreaName(“临颍”);
a11.setCityId(3);
areaList2.add(a11);
Area a12=newArea();
a12.setAreaId(22);
a12.setAreaName(“郾城”);
a12.setCityId(3);
areaList2.add(a12);
Area a13=newArea();
a13.setAreaId(12);
a13.setAreaName(“浦东”);
a13.setCityId(2);
areaList2.add(a13);
p2.setAreaList(areaList2);
personList.add(p2);
List cityIdList=new ArrayList<>();for(Person person:personList){for(Area area:person.getAreaList()){if(!cityIdList.contains(area.getCityId())){
cityIdList.add(area.getCityId());
}
}
}
List> myList= personList.stream().map(i->i.getAreaList().stream().map(area->area.getCityId()).collect(Collectors.toList())).collect(Collectors.toList());
Map> basicMap =personList.stream().collect(Collectors.groupingBy(Person::getPersonId));
List personListCurrent=basicMap.get(2);