//List里面的对象元素,以某个属性来分组,例如,以id分组,将id相同的放在一起 //List 以ID分组 Map<Long,List<Sku>> Map<Long, List<Sku>> mapList = skuList.stream().collect(Collectors.groupingBy(Sku::getProductSpecificationId)); System.out.println(mapList); //List转Map Map<Long, Sku> appleMap = skuList.stream().collect(Collectors.toMap(Sku::getProductSpecificationId, item -> item)); System.out.println(appleMap);