Online Java Compiler By
JavaTpoint.com
import java.util.*; public class EnumMapSizeExample2 { // 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); //print the number of mapping of this map System.out.println("Number of mappings: "+map.size()); //put one Key-value in this map map.put(Days.Thursday, "4"); //print the map System.out.println("Map: "+map); //print the new number of mappings of this map System.out.println("Number of mappings: "+map.size()); } }
Output