java 8 - stream, map and count distinct
问题 My first attempt with java 8 streams... I have an object Bid, which represents a bid of a user for an item in an auction. i have a list of bids, and i want to make a map that counts in how many (distinct) auctions the user made a bid. this is my take on it: bids.stream() .collect( Collectors.groupingBy( bid -> Bid::getBidderUserId, mapping(Bid::getAuctionId, Collectors.toSet()) ) ).entrySet().stream().collect(Collectors.toMap( e-> e.getKey(),e -> e.getValue().size()) ); It works, but i feel