码迷,mamicode.com
首页 > 其他好文 > 详细

HashMap和HashTable的区别是什么

时间:2019-02-14 23:51:59      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:默认   bst   nbsp   shm   性能   abs   不同   是什么   初始   

HashMap和HashTable的区别是什么

答:HashMap和HashTable分别继承了不同的类(HashMap继承AbstractMap,HashTable继承Dictionary)

HashMap是线程不安全的,HashTable是线程安全的

HashMap的性能比HashTable要高一些

HashMap的Key和Value可以存放null,HashTable的Key和Value不允许存放null

HashMap使用迭代器进行遍历,HashTable可以使用迭代器和枚举器进行遍历

HashMap和HashTable的遍历方式不同,HashMap遍历数组的方式是从头到尾,HashTable遍历数组的方式是从尾到头

HashMap默认初始容量为16,HashTable默认初始容量为11

HashMap扩容机制是 当前容量 * 2,HashTable扩容机制是 当前容量 * 2 +1

 

HashMap和HashTable的区别是什么

标签:默认   bst   nbsp   shm   性能   abs   不同   是什么   初始   

原文地址:https://www.cnblogs.com/TravisGrady/p/10381247.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!