VOOZH about

URL: https://www.geeksforgeeks.org/java/map-keyset-method-in-java-with-examples/

⇱ Map keySet() Method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Map keySet() Method in Java with Examples

Last Updated : 27 Nov, 2024

This method is used to return a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa.

Example:


Output
[1, 2]

Syntax of Method

Set keySet()

Parameters: This method has no argument.

Returns: This method returns a set containing keys of the specified map.

Example for Map keySet()

Below is the code to show implementation of hashCode():

Output:

{1=One, 3=Three, 5=Five, 7=Seven, 9=Nine}
[1, 3, 5, 7, 9]

Reference: Oracle Docs

Comment