stream map with Collectors.toMap vs Accumulator
问题 I have a a set of enums Set<Task> tasks; and process this to an EnumMap: Version 1 (using supplier, accumulator, combiner): return task.stream() .collect(() -> new EnumMap<>(Task.class), (map, item) -> map.put(item, compute(item)), Map::putAll); Version 2 (using Collectors.toMap): return tasks.stream().collect( Collectors.toMap( Function.identity(), t -> compute(t), null, () -> new EnumMap<>(Task.class))); I like version 1 more because it is shorter. However, I must select the fastest version