zoukankan      html  css  js  c++  java
  • 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();
    }
    

     

      

     

  • 相关阅读:
    【LeetCode每天一题】Pascal's Triangle(杨辉三角)
    【Redis】持久化
    【LeetCode每天一题】Swap Nodes in Pairs
    【LeetCode每天一题】Reverse String
    [bzoj2152]聪聪可可
    [bzoj3572][Hnoi2014]世界树
    Codeforces Round#409/VK-Cup 2017 Round2
    Educational Codeforces Round#19
    [bzoj4813][Cqoi2017]小Q的棋盘
    [bzoj4236]JOIOJI
  • 原文地址:https://www.cnblogs.com/prctice/p/5484979.html
Copyright © 2011-2022 走看看