Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12433912
  • 博文数量: 1293
  • 博客积分: 13501
  • 博客等级: 上将
  • 技术积分: 17974
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 18:11
文章分类

全部博文(1293)

文章存档

2019年(1)

2018年(1)

2016年(118)

2015年(257)

2014年(128)

2013年(222)

2012年(229)

2011年(337)

分类: Java

2014-12-19 11:39:56

一、hashtable hashmap使用测试过程


  1. private void testHashTable()
  2. {
  3.     Hashtable<String, Object> hTable = new Hashtable<String, Object>();
  4.     hTable.put("key0", "Value0");
  5.     hTable.put("key1", "Value1");
  6.     hTable.put("key0", "Value2");
  7. }


image

image


  1. private void testHastMap()
  2.     {
  3.         HashMap<String, Object> map = new HashMap<String, Object>();
  4.         map.put("ItemTitle", "第一次put ItemTitle value");
  5.         map.put("ItemText", "第一次put ItemText value");
  6.         map.put("ItemText", "第二次put ItemTitle value");
  7.     }


image

image


二、总结与结论

    由上面测试过程知,hashtable 和 hashmap是不存在key重复的概念的,因为后put的相同的key 集合,全自动将前面put进入的覆盖。这与C#的hashtable有区别,C#的hashtable如果add()了一个key进去,就不能再add同一个key进去了,除非你先remove再add

    另外,根据下面文章的原理分析,大多数情况下推荐使用hashmap。

 

三、参考文献-
详解两者原理区别:

http://blog.csdn.net/java2000_net/article/details/2512510

Hashtable 和 HashMap的区别

image

image

image

阅读(3240) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~