标签:源码 row throw war map 区别 线程 hashtable dex
HashMap允许key为null,Hashtable不允许key为null。
HashMap允许value为空,Hashtbale不允许value为null。
HashMap线程不安全,Hashtable线程安全。
4.Hashtable部分源码:
//使用了同步机制,线程安全 public synchronized V put(K key, V value) { // Make sure the value is not null if (value == null) {//value不允许为null throw new NullPointerException(); } // Makes sure the key is not already in the hashtable. Entry<?,?> tab[] = table; int hash = key.hashCode();//key不能为null int index = (hash & 0x7FFFFFFF) % tab.length; @SuppressWarnings("unchecked") Entry<K,V> entry = (Entry<K,V>)tab[index]; for(; entry != null ; entry = entry.next) { if ((entry.hash == hash) && entry.key.equals(key)) { V old = entry.value; entry.value = value; return old; } } addEntry(hash, key, value, index); return null; }
标签:源码 row throw war map 区别 线程 hashtable dex
原文地址:http://www.cnblogs.com/tonghun/p/7060834.html