M
M
Maxim Isaev2021-01-05 12:01:03
Java
Maxim Isaev, 2021-01-05 12:01:03

How to add VALUE value to HASHMAP if it is represented as ArrayList?

Good afternoon, there is a Hashmap>. If the key is contained in the hashmap, you need to add another collection to the current collection. I know only one AddAll method, but since it's boolean, doesn't work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-01-05
@MaximIs

You need to use the computeIfPresent
method And inside the lambda already calculate a new list using addAll, for example.
And if you also need to add an element, in the case when there is no key, just use compute

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question