Name

EnumMap<K extends Enum<K>,V>

Synopsis

This class is a Map implementation for use with enumerated types. The key type K must be an enumerated type, and all keys must be enumerated constants defined by that type. null keys are not permitted. The value type V is unrestricted and null values are permitted.

The EnumMap implementation is based on an array of elements of type V. The length of this array is the same as the number of constants defined by the enumerated type K. All Map operations execute in constant time. The iterators of the keySet( ), entrySet( ), and values( ) collections iterate their elements in the ordinal order of the enumerated constants. EnumMap is not threadsafe, but its iterators are based on a snapshot of the underlying array and never throw ConcurrentModificationException.

java.util.EnumMap<K extends Enum<K>,V>

Figure 16-16. java.util.EnumMap<K extends Enum<K>,V>

public class EnumMap<K extends Enum<K>,V> 
        extends AbstractMap<K,V> implements Serializable, Cloneable {
// Public Constructors
     public EnumMap(EnumMap<K,? extends V> m);  
     public EnumMap(Class<K> keyType);  
     public EnumMap(Map<K,? extends V> m);  
// Public Instance Methods
     public EnumMap<K,V> clone( );  
     public V put(K key, V value);  
// Public Methods Overriding AbstractMap
     public void clear( );  
     public boolean containsKey(Object key);  
     public boolean containsValue(Object value);  
     public Set<Map.Entry<K,V>> entrySet( );  
     public boolean equals(Object 

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.