LinkedHashMap entrySet() in Java

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

Syntax:

Set<Entry<K, V>> java.util.LinkedHashMap.entrySet()

This method returns a Set view of the mappings contained in this map.

Parameters: NA

Returns: a set view of the mappings contained in this map.

Exceptions: NA

Approach

Java

import java.util.LinkedHashMap;

public class LinkedHashMapentrySet {

    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.entrySet());
    }

}

Output:

[Java=1, Hello=2]


No comments:

Post a Comment