java資料結構 LinkedHashMap

2021-06-23 04:03:10 字數 860 閱讀 3852

通過名字,我們可以知道該資料結構具有hashmap的全部特性。

1. linkedhashmap繼承hashmap

public class linkedhashmapextends hashmapimplements map

2. linkedhashmap是乙個鍊錶結構,鍊錶的基本單元是entity

/**

* linkedhashmap entry.

*/private static class entryextends hashmap.entry{

// these fields comprise the doubly linked list used for iteration.

entrybefore, after;

在原來的基礎上,增加了 before和after兩個指標,所以這個鍊錶是乙個雙向鍊錶

所以linkedhashmap就是在原來的基礎上增加了一條鍊錶,這條鍊錶頭部是header

public class linkedhashmapextends hashmapimplements map{

private static final long serialversionuid = 3801124242820219131l;

/*** the head of the doubly linked list.

*/private transient entryheader;

這條鍊錶可以用來表示兩種順序:(1)access order (2)加入節點的順序

但是必須要在linkedhashmap的建構函式中確定鍊錶表示什麼順序

Java資料結構

arraylist 基於 array,在記憶體中占有連續空間,所以get index 時候,根據陣列首位址 偏移量就可以取到值 linklist 基於link,在記憶體中不連續,每個元素只知道下乙個元素,所以get時候,只能從首元素開始乙個乙個去找,效率相對較慢 增加刪除 arraylist 需要變...

java 資料結構

private void initmap log.d tag,map.tostring log.d tag,weakmap.tostring log.d tag,treemap.tostring log.d tag,hamap.tostring log.d tag,linkmap.tostring ...

java資料結構 佇列

1.用鍊錶實現單向佇列 package com.jzm.stackqueuetree public class linkqueue end constructor private class node end constructor private t getdata private node ge...