EnumMap is a specialized Map implementation for use with enum type keys. All of the keys in an enum map must come from a single enum type that is specified, explicitly or implicitly, when the map is created. Enum maps are represented internally as arrays. This representation is extremely compact and efficient.
Enum maps are maintained in the natural order of their keys (the order in which the enum constants are declared). This is reflected in the iterators returned by the collections views (keySet(), entrySet(), and values()). Null keys are not permitted. Attempts to insert a null key will throw
NullPointerException . Attempts to test for the presence of a null key or to remove one will, however, function properly. Null values are permitted.Declaration : public class EnumMap<K extends Enum<K>,V> Constructors : EnumMap(Class<K> keyType) Creates an empty enum map with the specified key type. EnumMap(EnumMap<K,? extends V> m) Creates an enum map with the same key type as the specified enum map, initially containing the same mappings (if any). EnumMap(Map<K,? extends V> m) Creates an enum map initialized from the specified map. EnumMap Methods :
EnumMapDemo CODE import java.util.*; OUTPUT {One=1, Two=2, Three=3, Four=4, Five=5} DESCRIPTION In the above program we have demonstrated the working of THINGS TO TRY
|