java collection

Java容器笔记(三):不同Map实现类的特点与区别

2017-05-23  本文已影响25人  maxwellyue

可以这样简单的来对待容器中Map的分类:


Map.png

仅讨论Java.util包中的常见Map类,不涉及java.util.concurrent中的并发Map类


接口和抽象类

A  Map that further provides a total ordering on its keys
A  SortedMap extended with navigation methods returning the closest matches 
for given search targets。
All of these methods are designed for locating, not traversing entries.
This class is obsolete.  New implementations should implement the Map interface, 
rather than extending this class

实现类

(1)HashMap默认的容量大小是16;增加容量时,每次将容量变为原始容量x2。
(2)HashMap添加元素时,是使用自定义的哈希算法。
(3)通过Iterator迭代器遍历时:“从前向后”的遍历数组;再对数组具体某一项对应的链表,从表头开始进行遍历。

(1)Hashtable默认的容量大小是11;增加容量时,每次将容量变为“原始容量x2 + 1”。
(2)Hashtable没有自定义哈希算法,而直接采用的key的hashCode()。
(3)通过Iterator迭代器遍历时:“从后向前”的遍历数组;再对数组具体某一项对应的链表,从表头开始进行遍历。


常见面试题


参考

未一一列出,待补充

上一篇下一篇

猜你喜欢

热点阅读