How to Check if key exists in HashMap

To check if Key exists in HashMap, we use the containsKey(Object key) method provided by HashMap.

boolean containsKey(Object key) searches the HashMap for the given key and returns boolean(true/false).

Lets see some examples on containsKey(Object key) method

Example : Check if Key exists in HashMap

Output

Reference

1. HashMap containsKey()