HashTable and HashMap
I. testing the use of hashtable hashmap
- Private void testHashTable ()
- {
- Hashtable <String, Object> hTable = new Hashtable <String, Object> ();
- HTable. put ("key0", "Value0 ");
- HTable. put ("key1", "Value1 ");
- HTable. put ("key0", "Value2 ");
- }
- Private void testHastMap ()
- {
- HashMap <String, Object> map = new HashMap <String, Object> ();
- Map. put ("ItemTitle", "first put ItemTitle value ");
- Map. put ("ItemText", "first put ItemText value ");
- Map. put ("ItemText", "Second put ItemTitle value ");
- }
Ii. Conclusion
According to the above test process, hashtable and hashmap do not have the concept of duplicate keys, because the same key set of the later put is automatically overwritten by the previous put. This is different from hashtable of C #. If hashtable of C # adds () A key, it cannot add the same key, unless you remove it first and then add it.
In addition, according to the principle analysis in the following article, hashmap is recommended in most cases.
Iii. References-
Differences between the two principles:
Http://blog.csdn.net/java2000_net/article/details/2512510
Differences between Hashtable and HashMap