EnumMap entrySet() in Java

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

Syntax:

Set<Entry<K, V>> java.util.EnumMap.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 enum map.

Exceptions: NA

Approach

Java

import java.util.EnumMap;

public class EnumMapentrySet {

    public enum Colour {
        RED, GREEN, YELLOW, ORANGE
    };

    public static void main(String[] args) {

        EnumMap<Colour, String> enumMap =
new EnumMap<Colour, String>(Colour.class);

        enumMap.put(Colour.RED, "Red");
        enumMap.put(Colour.GREEN, "Green");

        enumMap.put(Colour.YELLOW, "Yellow");
        enumMap.put(Colour.ORANGE, "Orange");

        System.out.println(enumMap.entrySet());

    }
}

Output:

[RED=Red, GREEN=Green, YELLOW=Yellow, ORANGE=Orange]


No comments:

Post a Comment