EnumMap values() in Java

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

Syntax:

Collection<V> java.util.EnumMap.values()

This method returns a Collection view of the values contained in this map.

Parameters: NA

Returns: a collection view of the values contained in this map.

Exceptions: NA

Approach

Java

import java.util.EnumMap;

public class EnumMapvalues {

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

    }
}

Output:

[Red, Green, Yellow, Orange]


No comments:

Post a Comment