HashSet,LinkedHashSet原始碼分析

2021-09-26 03:05:34 字數 1256 閱讀 7951

hashset 是乙個沒有重複元素的集合 。由hashmap實現,不保證元素的順序,允許null 。

private transient hashmapmap; 

//定義乙個靜態的object物件,來充當hashmap的value

private static final object present = new object();

public hashset()

public hashset(int initialcapacity, float loadfactor)

public hashset(int initialcapacity)

/*** 不對外公開的乙個構造方法(預設default修飾),底層構造的是linkedhashmap,提供給linkedhashset使用。dummy無具體意義

*/hashset( int initialcapacity, float loadfactor, boolean dummy)

hashset的其他方法,如add(),remove(),size(),都是呼叫了hashmap方法

public boolean add(e e) 

public boolean contains(object o)

繼承hashset,沒有重複元素,可以保持元素的插入順序(linkedhashmap可以維護插入順序或訪問順序,linkedhashset只維護插入順序)

構造方法:

public linkedhashset(int initialcapacity, float loadfactor) 

public linkedhashset(int initialcapacity)

public linkedhashset()

這三個構造方法都呼叫了hashset類中 hashset( int initialcapacity, float loadfactor, boolean dummy) 的構造方法。

hashset( int initialcapacity, float loadfactor, boolean dummy)
public linkedhashmap(int initialcapacity, float loadfactor)
該方法中建立了乙個linkedhashmap物件,且accessorder=false,即維護插入順序。

Cartographer原始碼篇 原始碼分析 1

在安裝編譯cartographer 1.0.0的時候,我們可以看到 主要包括cartorgarpher ros cartographer ceres sover三個部分。其中,ceres solver用於非線性優化,求解最小二乘問題 cartographer ros為ros平台的封裝,獲取感測器資料...

AbstractListView原始碼分析3

normal list that does not indicate choices public static final int choice mode none 0 the list allows up to one choice public static final int choice ...

Android AsyncTask原始碼分析

android中只能在主線程中進行ui操作,如果是其它子執行緒,需要借助非同步訊息處理機制handler。除此之外,還有個非常方便的asynctask類,這個類內部封裝了handler和執行緒池。本文先簡要介紹asynctask的用法,然後分析具體實現。asynctask是乙個抽象類,我們需要建立子...