If your ending map has a chance of “duplicate keys”, there is a better solution using
toMap(Function<? super T, ? extends K> keyMapper,
Function<? super T, ? extends U> valueMapper,
BinaryOperator<U> mergeFunction,
Supplier<M> mapSupplier)
You could use it like this:
HashMap<Set<Integer>, Double> map = container.entrySet()
.stream()
.filter(k -> k.getKey().size() == size)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (prev, next) -> next, HashMap::new));
Then as duplicate keys are added, it will use the latest instead of throwing an exception. The last parameter is optional.
If you want to keep duplicate keys into a list, then use Collectors.groupingBy
instead.