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 * 如果键不 ...
随机推荐
- 【IT笔试面试题整理】判断链表是否存在环路,并找出回路起点
[试题描述]定义一个函数,输入一个链表,判断链表是否存在环路,并找出回路起点 Circular linked list: A (corrupt) linked list in which a node ...
- Android studio的gradle
1. gradle的基本概念 gradle构建* Android Studio使用`Gradle`构建工具,Eclipse的ADT插件使用的是`Ant`构建工具* 构建:生成app的过程,执行一些的命 ...
- 从零开始学JAVA(09)-使用SpringMVC4 + Mybatis + MySql 例子(注解方式开发)
项目需要,继续学习springmvc,这里加入Mybatis对数据库的访问,并写下一个简单的例子便于以后学习,希望对看的人有帮助.上一篇被移出博客主页,这一篇努力排版整齐,更原创,希望不要再被移出主页 ...
- 找xpath好用的工具(Firefox插件)
WebDriver Element Locator 安装 打开firefox浏览器,进入网址https://addons.mozilla.org/en-US/firefox/ 在搜索框里输入WebDr ...
- Tunnel Warfare(hdu1540 线段树)
Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- 记一次SQL注入实战
刚发现漏洞时,我就已经成功实现了注入,因为怕发到网上后被玩坏,一直没有发布.今天去看了看,原网页已经无法访问了,现在发出来应该就没有什么大问题了. 本文仅供学习交流,目的是为了构建更加安全的网络环境! ...
- 【C#数据结构系列】栈和队列
一:栈 栈和队列也是线性结构,线性表.栈和队列这三种数据结构的数据元素以及数据元素间的逻辑关系完全相同,差别是线性表的操作不受限制,而栈和队列的操作受到限制.栈的操作只能在表的一端进行,队列的插入操作 ...
- SSM整合的pom.xml依赖
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- linux_shell_入门
shell编程入门: 程序员标配:第一个shell脚本 输出 ---- " Hello World !!" 1.先创建一个hello.sh脚本文件 vi hello.sh 然后在输 ...
- vue-infinite-loading2.0 中文文档
简介 这是一个使用在Vue.js中的无限滚动插件,它可以帮助你快速创建一个无限滚动列表. 特点 移动端支持友好 兼容任何一个可以滚动的元素 有不同的旋转器可以作为加载动画 支持加载后显示结果 支持两个 ...