keySet(): This method is available in java.util.HashMap class of Java.
Syntax:
Set<K> java.util.HashMap.keySet()
This method returns a Set view of the keys contained in this map.
Parameters: NA
Returns: a set view of the keys contained in this map.
Exceptions: NA
Approach
Java
import java.util.HashMap;public class HashMapkeySet {public static void main(String[] args) {HashMap<String, Integer> hashMap =new HashMap<String, Integer>();hashMap.put("Hello", 1);hashMap.put("World", 2);System.out.println(hashMap.keySet());}}
Output:
[Hello, World]
No comments:
Post a Comment