Skip to content
Advertisement

HashMap value auto increment

when I was coding, one question occurred to me, which is if the value part(Integer) in the HashMap is able to auto-increment in the following scenario?

JavaScript

Advertisement

Answer

Consider using an AtomicInteger:

JavaScript

Also consider using a for loop to simplify the code.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement