夜深了,快睡吧-ConcurrentHashMap

2018-08-08  本文已影响9人  一个喜欢烧砖的人
基本使用
public static void main(String[] args) {

        ConcurrentHashMap<String, String> cHashMap = new ConcurrentHashMap<String, String>();
        cHashMap.put("cn", "中国");
        cHashMap.put("jp", "日本");
        cHashMap.put("fr", "法国");
        cHashMap.put("cn", "中国2号");
//        cHashMap.put(null,"fds");//报null
//        cHashMap.put("df",null);//报 null
        System.out.println(cHashMap);
        System.out.println(cHashMap.toString());
        System.out.println("****");
        Iterator i = cHashMap.keySet().iterator();
        while (i.hasNext()) {
            String k = (String) i.next();
            String v = cHashMap.get(k);
            System.out.println("k:" + k + "v:" + v);
        }
    }

运行结果

{jp=日本, cn=中国2号, fr=法国}
{jp=日本, cn=中国2号, fr=法国}
****
k:jpv:日本
k:cnv:中国2号
k:frv:法国
总结
* @param <V> the type of mapped values
 */
public class ConcurrentHashMap<K,V> extends AbstractMap<K,V>
    implements ConcurrentMap<K,V>, Serializable {
    private static final long serialVersionUID = 7249069246763182397L;

    /*
     * Overview:
     *
     * The primary design goal of this hash table is 
上一篇 下一篇

猜你喜欢

热点阅读