java数据结构-LinkedHashMap

本文详细介绍了LinkedHashMap这一数据结构,它是HashMap的一种扩展实现,通过在原有的基础上增加一条双向链表来保持元素的插入或访问顺序。文章解释了LinkedHashMap如何继承自HashMap,并探讨了其内部的Entry结构是如何支持这种特性的。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

通过名字,我们可以知道该数据结构具有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的构造函数中确定链表表示什么顺序

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值