226k views
5 votes
What is the signature of a Map method that returns a data set of all the keys in the map?

a) Set getAllKeys()
b) List getKeys()
c) Map keys()
d) Collection retrieveKeys()

User Eugensk
by
7.9k points

1 Answer

6 votes

Final answer:

The correct signature of a Map method that returns a data set of all the keys in the map is keySet(). This method returns a Set collection of all the keys in the map.

Step-by-step explanation:

The correct signature of a Map method that returns a data set of all the keys in the map is Set<K> keySet(). This method returns a Set collection of all the keys in the map.

For example, if you have a Map<String, Integer> called studentScores, you can call the keySet() method to get a Set of all the keys:

Map<String, Integer> studentScores = new HashMap<>();
Set<String> keys = studentScores.keySet();
User Josh Smith
by
8.2k points