public static void main(String[] args) {
List<AnoleIntersection> intersections = new ArrayList<AnoleIntersection>() {
{
add(new AnoleIntersection() {{this.setId(1L);this.setTypeId(1L);}});
add(new AnoleIntersection() {{this.setId(2L);this.setTypeId(1L);}});
add(new AnoleIntersection() {{this.setId(3L);this.setTypeId(3L);}});
add(new AnoleIntersection() {{this.setId(4L);this.setTypeId(4L);}});
add(new AnoleIntersection() {{this.setId(5L);this.setTypeId(4L);}});
add(new AnoleIntersection() {{this.setId(6L);this.setTypeId(6L);}});
add(new AnoleIntersection() {{this.setId(7L);this.setTypeId(7L);}});
add(new AnoleIntersection() {{this.setId(8L);this.setTypeId(1L);}});
}
};
Map<Long, List<AnoleIntersection>> map = intersections.stream().collect(Collectors.groupingBy(AnoleIntersection::getTypeId));
System.out.println(JSONObject.toJSONString(map));
}
快速创建list并生成map
最新推荐文章于 2024-10-19 06:09:15 发布