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 * 如果键不 ...
随机推荐
- python3.X出现关于模块(i18n)的不能使用的解决方法
今天在看python编程从入门到实践的时候,遇到了 如下问题 ModuleNotFoundError: No module named 'pygal.i18n' 然后查找文献找到一个网友 的解决 ...
- Deep learning with Python 学习笔记(6)
本节介绍循环神经网络及其优化 循环神经网络(RNN,recurrent neural network)处理序列的方式是,遍历所有序列元素,并保存一个状态(state),其中包含与已查看内容相关的信息. ...
- Excel核心技巧【干货】
进入职场后发现,几乎有很大一部分时间都耗在了表格上. Excel的存在是为了更高效工作,但庞大的数据处理却成了你每晚加班的“凶手”? 其实,从数据整理到数据分析,只要掌握20%的Excel技巧,就足以 ...
- Java基本数据类型总结(转载)
Java基本数据类型总结 基本类型,或者叫做内置类型,是JAVA中不同于类的特殊类型.它们是我们编程中使用最频繁的类型.java是一种强类型语言,第一次申明变量必须说明数据类型,第一次变量赋值称为变量 ...
- 临时表 on commit delete rows 与 on commit preserve rows 的区别
-- 事务级临时表:提交时删除数据 create global temporary table tmp_table1 ( x number ) on commit delete ...
- Oracle总结之plsql编程(基础八)
原创作品,转自请注明出处:https://www.cnblogs.com/sunshine5683/p/10328524.html 一.函数 1.函数是可以返回一个特定的数据,函数的创建中必须包含re ...
- __int64 与long long 的区别
//为了和DSP兼容,TSint64和TUint64设置成TSint40和TUint40一样的数 //结果VC中还是认为是32位的,显然不合适 //typedef signed long int ...
- NIO学习笔记五:Buffer 的使用
Java NIO中的Buffer用于和NIO通道进行交互.数据是从通道读入缓冲区,从缓冲区写入到通道中. 缓冲区本质上是一块可以写入数据,然后可以从中读取数据的内存.这块内存被包装成NIO Buffe ...
- Linux常用基本命令(paste)
paste命令 作用:合并文件 格式: paste [option] [file] 1,把两个文件的内容,按行合并 ghostwu@dev:~/linux/paste$ ls ghostwu1.txt ...
- js字符串如何倒序
1. var reverse = function( str ){ var newStr = '', i = str.length; for(; i >= 0; i--) { newStr += ...