Online Java Compiler By
JavaTpoint.com
import java.util.*; public class EnumMapPutExample3 { // create an enum public enum Days { Monday,Tuesday, Wednesday, Thursday }; public static void main(String[] args) { EnumMap
map = new EnumMap
(Days.class); map.put(Days.Monday, "1"); map.put(Days.Tuesday, "2"); map.put(Days.Wednesday, "3"); //print the map System.out.println("Map: "+map); String oldValue1 = map.put(Days.Thursday, "4"); String oldValue2 = map.put(null, "9"); //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