Skip to content

Conversation

turbanoff
Copy link
Contributor

Map.containsKey calls are often unnecessary.
Depends on the code, we can:

  1. call get() and then compare result with null. Applicable if we know that Map don't contain null value
  2. use putIfAbsent()/computeIfAbsent() if containsKey() was used before put
  3. use getOrDefault() if we have "fallback" value

I believe it simplifies code and makes it a bit faster.

Map.containsKey calls are often unnecessary.
Depends on the code, we can:
 1. call get() and then compare result with null. Applicable if we know that Map don't contain null value
 2. use putIfAbsent()/computeIfAbsent() if containsKey() was used before put
 3. use getOrDefault() if we have "fallback" value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant