LinkedHashMap keySet() in Java

keySet(): This method is available in java.util.LinkedHashMap class of Java.

Syntax:

Set<K> java.util.LinkedHashMap.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.LinkedHashMap;

public class LinkedHashMapkeySet {

    public static void main(String args[]) {

        LinkedHashMap<String, Integer> linkedHashMap =
new LinkedHashMap<String, Integer>();

        linkedHashMap.put("Java", 1);
        linkedHashMap.put("Hello", 2);

        System.out.println(linkedHashMap.keySet());

    }

}

Output:

[Java, Hello]


No comments:

Post a Comment