HashTable之put
来源:互联网 发布:类似菠萝饭的软件 编辑:程序博客网 时间:2024/05/18 08:40
package lattice;import java.util.Hashtable;public class TestHashTable{public static void main(String[] args){Hashtable<String, Integer>hashtable=new Hashtable<>();String str=new String("w3ang");hashtable.put(str,1);hashtable.put(str,2);hashtable.put("xd", 3);hashtable.put("hn", 3);//System.out.println(hashtable.keySet().toString());System.out.println(hashtable.entrySet().toString());//Out:[w3ang=2, xd=3, hn=3]}}
源码:
/** * Maps the specified <code>key</code> to the specified * <code>value</code> in this hashtable. Neither the key nor the * value can be <code>null</code>. <p> * * The value can be retrieved by calling the <code>get</code> method * with a key that is equal to the original key. * * @param key the hashtable key * @param value the value * @return the previous value of the specified key in this hashtable, * or <code>null</code> if it did not have one * @exception NullPointerException if the key or value is * <code>null</code> * @see Object#equals(Object) * @see #get(Object) */ public synchronized V put(K key, V value) { // Make sure the value is not null if (value == null) { throw new NullPointerException(); } // Makes sure the key is not already in the hashtable. Entry<?,?> tab[] = table; int hash = key.hashCode(); 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; }
0 0
- HashTable之put
- java hashtable的put方法
- Http方法之PUT
- Python之put接口
- HBase CURD之Put
- 从源码层理解Hashtable中的put和get
- leveldb之Put、Get操作
- aerospike实战之put操作
- leveldb之Put、Get操作
- Ignite Debug之put操作
- HBase分析之Put操作
- put ()
- python之raw_input和put之区别
- JCF之Hashtable剖析
- java 之 哈希表类 HashTable
- 集合之SortedList+Hashtable
- Matlab杂记之 HashTable
- memcached 之hashtable【转】
- 树的非递归遍历(很易懂)
- BestCoder #92 C (dp)(要学会表示状态啊)
- Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition(SPP-Net)解读
- bzoj 3333 树状数组+线段树
- 《CLR via C#》读书笔记-CLR寄宿与AppDomain
- HashTable之put
- HDU---1114 Piggy-Bank【完全背包】
- android-view(3)
- NYOJ 260
- 反射
- Kanzi基础---Kanzi基本概念
- 括号匹配 RMQ/暴力
- mysql之简单的多标查询
- C++智能指针详解