toString(): This method is available in java.util.EnumMap class of Java.
Syntax:
String java.util.AbstractMap.toString()
This method returns a string representation of this map.
Parameters: NA
Returns: a string representation of this map.
Exceptions: NA
Approach
Java
public class EnumMaptoString {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.toString());}}
Output:
{RED=Red, GREEN=Green, YELLOW=Yellow, ORANGE=Orange}
No comments:
Post a Comment