Differences between Collectors.toMap() and Collectors.groupingBy() to collect into a Map
TLDR : To collect into a Map that contains a single value by key (Map<MyKey,MyObject>), use Collectors.toMap(). To collect into a Map that contains multiple values by key (Map<MyKey, List<MyObject>>), use Collectors.groupingBy(). Collectors.toMap() By writing : chargePoints.stream().collect(Collectors.toMap(Point::getParentId, c -> c)); The returned object will have the Map<Long,Point> type. Look at the Collectors.toMap() function that you … Read more