Skip to content
Sharp

Concurrency basics · interview question

When using a ConcurrentHashMap, what happens if you attempt to insert a null value?

Multiple choiceMediumchapter-15-curatedpremiumconcurrencyconcurrent-collections
Choose one answer
Answer and explanation

Correct answer

C. The map throws a NullPointerException.

Why

ConcurrentHashMap does not allow null keys or values and will throw a NullPointerException if you attempt to insert a null value.

Test yourself on Concurrency basics

A free test with instant, explained results. No account needed.

Start free test
All Concurrency basics questions →