Lambada笔记分享

  1. 重复键的去除。
Map restaurantMap = restaurants.stream().collect(Collectors.toMap(Restaurant::getElemeRestaurantId, Restaurant::getStoreId, (key1, key2) -> key2));

  1. List 以ID分组 Map>
Map> groupBy = appleList.stream().collect(Collectors.groupingBy(Apple::getId)); 
  1. List以ID分组后聚合对象的一个属性
        Map> restaurantMap = restaurants.stream().collect(Collectors.toMap(
                Restaurant::getStoreId,
                r -> Collections.singletonList(r.getElemeRestaurantId()),
                (x, y) -> {
                    List l = new ArrayList<>();
                    l.addAll(y);
                    return l;
                }
        ));

你可能感兴趣的:(Lambada笔记分享)