快速创建list并生成map

public static void main(String[] args) {
	List intersections = new ArrayList() {
		{
			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> map = intersections.stream().collect(Collectors.groupingBy(AnoleIntersection::getTypeId));
	System.out.println(JSONObject.toJSONString(map));
}

你可能感兴趣的:(java)