I am trying to use a Java HashMap
. Using map.get("A")
to get a value for a key from the map resulted in a NullPointerException
. Then I used if(map.get("A"))
to avoid a NullPointerException
being thrown, but it gets thrown anyway.
What am I doing wrong?
I have answering my own question. I have used to check
if(map.containsKey("A"))
String b = map.get("A")
rather than
if(map.get("A") != null)
map.get("A")
It will help me to avoid null pointer exception
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With