What is LinkedHashMap?

后端 未结 6 1395
迷失自我
迷失自我 2021-02-02 00:02

Ok so i am new to these HashMaps but have some idea about LinkedLists and HashMaps. It would be great if you could give me some simple explanation regarding LinkedHashMap and a

6条回答
  •  Happy的楠姐
    2021-02-02 01:00

    It is a hybrid of two data structures, a LinkedList, where insertion order is preserved by adding elements to the end of a list of nodes which have access to their immediate neighbours, and a HashMap, or a Map that uses an array of bucket Lists, where a modulus division remainder of the key's hashcode() determines the starting bucket to query for the equals() method of the keys that lie in that bucket's list of contents.

    The advantage is that you can walk the existing elements in a HashMap in order of insertion, due to the LinkedList nature, and you can quickly jump to the correct bucket in a key lookup (saving a lot of time for a large collection) if you have the key of the element.

提交回复
热议问题