java数据结构-LinkedHashMap

来源:互联网 发布:动态效果图制作软件 编辑:程序博客网 时间:2024/06/05 15:59

通过名字,我们可以知道该数据结构具有hashmap的全部特性。
1. LinkedHashMap继承HashMap

public class LinkedHashMap<K,V>    extends HashMap<K,V>    implements Map<K,V>

2. LinkedHashMap是一个链表结构,链表的基本单元是Entity

/**     * LinkedHashMap entry.     */    private static class Entry<K,V> extends HashMap.Entry<K,V> {        // These fields comprise the doubly linked list used for iteration.        Entry<K,V> before, after;
在原来的基础上,增加了 before和after两个指针,所以这个链表是一个双向链表

所以LinkedHashMap就是在原来的基础上增加了一条链表,这条链表头部是header

public class LinkedHashMap<K,V>    extends HashMap<K,V>    implements Map<K,V>{    private static final long serialVersionUID = 3801124242820219131L;    /**     * The head of the doubly linked list.     */    private transient Entry<K,V> header;
这条链表可以用来表示两种顺序:(1)access order (2)加入节点的顺序

但是必须要在LinkedHashMap的构造函数中确定链表表示什么顺序

0 0
原创粉丝点击