Online Java Compiler By
JavaTpoint.com
import java.util.*; public class EnumMapPutExample2 { // create an enum public enum Months { January, February, March, April, May }; public static void main(String[] args) { //create and populate enum map EnumMap< Months, String> map = new EnumMap< Months, String> (Months.class); map.put(Months.January,"1"); map.put(Months.February,"2"); map.put(Months.March,"3"); map.put(Months.April,"4"); //print the map System.out.println("Map: "+map); String oldValue1 = map.put(Months.May, "5"); String oldValue2 = map.put(Months.March, "15"); //print the updated map System.out.println("Updated Map: "+map); System.out.println("First update returns: "+oldValue1); System.out.println("Second update returns: "+oldValue2); } }
Output