java集合类分析-map

不同于list还有set的单个元素的组织形式,map要求的保存的是一个组对象,也即使键值对。对jdk中的map源码是比较重要的,因为通过分析jdkset的源码可以发现其实就是map的一层包装,实际上底层都是在调用map的具体实现的操作。

 

public interface Map<K,V> {
    // Query Operations
//返回map的大小
   int size();
   //判断map是否为空
   boolean isEmpty();
//是否包含该键值
    boolean containsKey(Object key);
//是否包含该值
    boolean containsValue(Object value);

    //返回键值为key的对象的值
    V get(Object key);

// Modification Operations
//插入键值对
    V put(K key, V value);
//删除
    V remove(Object key);


    // Bulk Operations
  	//添加m中的元素到map中去
    void putAll(Map<? extends K, ? extends V> m);
//清空
    void clear();


    // Views
//返回key集合
    Set<K> keySet();
//返回值集合
    Collection<V> values();

   //返回键值对集合
    Set<Map.Entry<K, V>> entrySet();

    // 键值对操作接口
    interface Entry<K,V> {
       //返回key
        K getKey();
//返回value
        V getValue();
//设置value
        V setValue(V value);

        boolean equals(Object o);

        /**
         * Returns the hash code value for this map entry.  The hash code
         * of a map entry <tt>e</tt> is defined to be: <pre>
         *     (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
         *     (e.getValue()==null ? 0 : e.getValue().hashCode())
         * </pre>
         * This ensures that <tt>e1.equals(e2)</tt> implies that
         * <tt>e1.hashCode()==e2.hashCode()</tt> for any two Entries
         * <tt>e1</tt> and <tt>e2</tt>, as required by the general
         * contract of <tt>Object.hashCode</tt>.
     */
        int hashCode();
    }
    // Comparison and hashing
    boolean equals(Object o);
    int hashCode();
}

 

  

 

posted on 2016-05-12 11:24  duoyu  阅读(164)  评论(0编辑  收藏  举报

导航