📜  Java.util.EnumMap类

📅  最后修改于: 2020-11-14 06:15:26             🧑  作者: Mango


介绍

java.util.EnumMap类是用于枚举键的特殊Map实现。以下是有关EnumMap的要点-

  • 枚举映射中的所有键都必须来自创建映射时显式或隐式指定的单个枚举类型。

  • 枚举映射按其键的自然顺序维护。

  • EnumMap不同步。如果多个线程同时访问一个枚举映射,并且至少有一个线程修改了该映射,则应在外部进行同步。

类声明

以下是java.util.EnumMap类的声明-

public class EnumMap,V>
   extends AbstractMap
   implements Serializable, Cloneable

类的构造函数

Sr.No. Constructor & Description
1

EnumMap(Class keyType)

This constructor creates an empty enum map with the specified key type.

2

EnumMap(EnumMap m)

This constructor creates an enum map with the same key type as the specified enum map, initially containing the same mappings (if any).

3

EnumMap(Map m)

This constructor creates an enum map initialized from the specified map.

类方法

Sr.No. Method & Description
1 void clear()

This method removes all mappings from this map.

2 EnumMap clone()

This method returns a shallow copy of this enum map.

3 boolean containsKey(Object key)

This method returns true if this map contains a mapping for the specified key.

4 boolean containsValue(Object value)

This method returns true if this map maps one or more keys to the specified value.

5 Set> entrySet()

This method returns a Set view of the mappings contained in this map.

6 boolean equals(Object o)

This method compares the specified object with this map for equality.

7 V get(Object key)

This method returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

8 Set keySet()

This method returns a Set view of the keys contained in this map.

9 V put(K key, V value)

This method associates the specified value with the specified key in this map.

10 void putAll(Map m)

This method Copies all of the mappings from the specified map to this map.

11 V remove(Object key)

This method removes the mapping for this key from this map if present.

12 int size()

This method returns the number of key-value mappings in this map.

13 Collection values()

This method returns a Collection view of the values contained in this map.

方法继承

此类从以下类继承方法-

  • java.util.AbstractMap
  • java.util.Object