Difference between HashMap and Hashtable | HashMap Vs Hashtable
Both the HashMap and Hashtable implement the interface java.util.Map but there are some slight differences which has to be known to write a much efficient code.
- The Most important difference between HashMap and the Hashtable is that Hashtable is synchronized and HashMap is non-synchronized , which means Hashtable is thread-safe and can be shared among multiple threads and you don’t need to worry about the synchronization problems. As only one thread can access the Hashtable at a time whereas Hashmap is not thread-safe and it cannot be shared between threads without synchronization. You can synchronize the HashMap using this below code.
Map m = Collections.synchronizedMap(hashMap);
- HashMap permits one null key and multiple null values whereas the Hashtable will not allow null key or value.
- Since the Hashtable is thread-safe it is comparatively slower than the HashMap in the environment where Synchronization factor is not considered.
- HashMap can be traversed by using the iterator, whereas the Hashtable can be traversed by using enumerator and iterator.
- HashMap inherits AbstractMap class and Hashtable inherits Dictionary class.
Filed Under: Java, Java InterviewTagged With: difference, hashmap, hashmap and hashtable, hashtable, synchronization, thread-safe
Difference between HashMap and Hashtable | HashMap Vs Hashtable的更多相关文章
- HashSet HashTable HashMap的区别 及其Java集合介绍
(1)HashSet是set的一个实现类,hashMap是Map的一个实现类,同时hashMap是hashTable的替代品(为什么后面会讲到). (2)HashSet以对象作为元素,而HashMap ...
- Hashtable,HashMap实现原理
http://blog.csdn.net/czh0766/article/details/5260360 昨天看了算法导论对散列表的介绍,今天看了一下Hashtable, HashMap这两个类的源代 ...
- C# Hashtable 使用说明 以及 Hashtable和HashMap的区别
一,哈希表(Hashtable)简述 在.NET Framework中,Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现类似key/value的键值对,其 ...
- java该HashTable,HashMap和HashSet
同一时候我们也对HashSet和HashMap的核心方法hashcode进行了具体解释,见<探索equals()和hashCode()方法>. 万事俱备,那么以下我们就对基于hash算法的 ...
- 多线程之Map:Hashtable HashMap 以及ConcurrentHashMap
1.Map体系参考:http://java.chinaitlab.com/line/914247.htmlHashtable是JDK 5之前Map唯一线程安全的内置实现(Collections.syn ...
- 为什么HashMap线程不安全,Hashtable和ConcurrentHashMap线程安全
HashMap源码 public V put(K key, V value) { return putVal(hash(key), key, value, false, true); } final ...
- HashTable & HashMap & ConcurrentHashMap 原理与区别
一.三者的区别 HashTable HashMap ConcurrentHashMap 底层数据结构 数组+链表 数组+链表 数组+链表 key可为空 否 是 否 value可为空 否 是 否 ...
- Hashtable,HashMap,TreeMap有什么区别?Vector,ArrayList,LinkedList有什么区别?int和Integer有什么区别?
接着上篇继续更新. /*请尊重作者劳动成果,转载请标明原文链接:*/ /*https://www.cnblogs.com/jpcflyer/p/10759447.html* / 题目一:Hashtab ...
- 10 HashMap,Map.Entry,LinkedHashMap,TreeMap,Hashtable,Collections类
Map集合的功能概述 添加功能 * V put(K key,V value):添加元素. * 如果键是第一次存储,就直接存储元素,返回null * 如果键不 ...
随机推荐
- gateway-workman
最外层start.php,设置全局启动模式,加载Application里的个子服务目录下应用的启动文件(start开头,这些文件都是workman\work类的子类,在载入文件的同时,这些子服务会生成 ...
- Conditional特性用法
说明:根据预处理标识符执行方法.Conditional 特性是 ConditionalAttribute 的别名,可应用于方法或属性类.相对于#if和#endif,更灵活更简洁和不易出错. 例如: # ...
- C字符串
C字符串 C中的字符串是以空字符('\0')结尾的一个char数组,基本的实现字符串的方法有:字符串常量,字符串数组,char数组,char指针.字符串使用广泛,如与用户交互等处理自然语言的情况.C为 ...
- [JSOI 2007]字符加密Cipher
Description 题库链接 给你一个长度为 \(n\) 的字符串,首尾相接依次断开每个断点可以得到 \(n\) 个长度为 \(n\) 的字符串,将其排序按序输出每个字符串的最后一个字母. \(1 ...
- Html.DropDownListFor练习
今天练习Html.DropDownListFor(). 在网页开发过程中,这个DropDownList功能定会少不了.让用户能显式选择需求的选项.先来看看下面实时操作,Category这个字段是一个外 ...
- 微信小程序开源Demo精选
来自:http://www.jianshu.com/p/0ecf5aba79e1 文/weapphome(简书作者)原文链接:http://www.jianshu.com/p/0ecf5aba79e1 ...
- 【C#数据结构系列】排序
一:排序 排序(Sort)是计算机程序设计中的一种重要操作,也是日常生活中经常遇到的问题.例如,字典中的单词是以字母的顺序排列,否则,使用起来非常困难.同样,存储在计算机中的数据的次序,对于处理这些数 ...
- 在pycharm中进行ORM操作
打开manage.py, 复制 import..... if.......os..... 导入django,开启django, 导入app中的models orm操作 import os if _ ...
- 'QuerySet' object has no attribute '_meta'
'QuerySet' object has no attribute '_meta' 对象列表没有'_meta'属性 单独的对象才有, 忘记加first了 edit_obj = models.Role ...
- 精选20个高品质的免费素材,可以下载PSD格式
GraphicBurger 这个站点免费和收费的都有,注意区分 365psd 在日本比较有名的免费素材站. Pixeden Techandall Premium pixels 全部免费! Design ...