148k views
3 votes
What is the signature of a Map method that checks if a key exists in the Map?

a) boolean hasKey(K key)
b) boolean contains(K key)
c) K checkKey(K key)
d) V checkValue(V value)

User KrzysDan
by
7.6k points

1 Answer

3 votes

Final answer:

The Map method to check if a key exists is called containsKey with the signature boolean containsKey(Object key).

Step-by-step explanation:

The method in the Map interface that checks if a certain key exists is called containsKey. The correct signature for this method is boolean containsKey(Object key). It returns true if the map contains a mapping for the specified key, and false if it does not. This method is very useful for avoiding exceptions that are thrown when trying to access a value using a non-existent key.

User Teter
by
7.5k points