一、java集合框架类之Map
Map是一种常见的集合类,存储的元素是几月键值树对的形式即:key-->value ,这种形式的元素对。
Map作为一个接口,定义了如下的通用的方法:public interface Map<K,V>
int size();//return the number of key-value mappings in this map
boolean isEmpty();//return true if this map contains no key-value mappings
boolean containsKey(Object key);//return true if this map contains a mapping for the specified key
boolean containsValue(Object value);//return true if this map maps one or more keys to the specified value
V get(Object key);//return the value to which the specified key is mapped, or null if this map contains no mapping for the key
V put(Key key, V value);
V remove(Object key);//return the previous value associated with key, or null if there was no mapping for key
void putAll(Map<? extends K, ? extends V> m);//copies all of the mappings from the map m to this map.
void clear();//Removes all of the mappings from this map
Set<K> keySet();// return a view of the keys contained in this map.
Collection<V> valus();// return a view of the values contained int this map.
Set<Map.Entry<K,V>> entrySet();//return a set view of the mappings contained int this map.
然后,包含一个内部接口:
interface Entry<K,V> {
K getKey();
V getValue();
V setValye(V valye);
boolean equals(Object o);
int hashCode();
}
/
然后是抽象的AbstractMap<K,V> 实现了Map接口,AbstractMap抽象了Map这个事物,提供了Map接口的骨干实现,从而最大限度的减少了实现此接口所需要的工作。
直接已知子类有:ConcurrentHashMap,EnumMap,HashMap,IdentifyHashMap,TreeeMap,WeakHashMap.
接下来的几节中,分别介绍具体的子类及其特点。
下一篇介绍:HashMap
Java CollectionFrameWork -- Map
最新推荐文章于 2024-09-23 10:19:41 发布