How do I update the value with the key value in Java hashMap?

Asked 1 years ago, Updated 1 years ago, 96 views

Assuming there is a HashMap, how do I find the value of Integer as the string key value and update the value? The way to remove the existing value and enter a new one is concerned about overhead. The alternative is to replace the old value with a new pair. What I want is to find the key value and increase the value by 1.

java hashmap key

2022-09-22 22:25

1 Answers

map.put(key, map.get(key) + 1); You can do it in this way.


2022-09-22 22:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.