HashMap,LinkedHashMap,TreeMap區別
注:去年專案有用到LinkedHashMap,最開始忘記這個,浪費了點時間,剛好看到阿里開發手冊,記錄一下區別。
HashMap
最多隻允許一條記錄的鍵為Null;允許多條記錄的值為 Null
非執行緒安全
LinkedHashMap
儲存了記錄的插入順序,在用Iterator遍歷LinkedHashMap時,先得到的記錄肯定是先插入的。
TreeMap
存入元素的時候,自動對元素根據鍵進行升序排序
非執行緒安全
總結
正常情況下,使用HashMap,有其他需求,再使用LinkedHashMap和TreeMap
集合 | Key | Value | 執行緒安全 |
TreeMap | 不允許為null | 允許為null | 非執行緒安全 |
HashMap | 允許為null | 允許為null | 非執行緒安全 |
LindedHashMap | 允許為null | 允許為null | 非執行緒安全 |
HashTable | 不允許為null | 不允許為null | 執行緒安全(效率低) |
相關推薦
HashMap,LinkedHashMap,TreeMap區別
注:去年專案有用到LinkedHashMap,最開始忘記這個,浪費了點時間,剛好看到阿里開發手冊,記錄一下區別。 HashMap 最多隻允許一條記錄的鍵為Null;允許多條記錄的值為 Null 非執行緒安全 LinkedHashMap 儲存了記錄的插入
2018.9.30學習筆記(Map,HashMap,LinkedHashMap,TreeMap)
1 Map 單列集合底層是雙列集合 2 Map的基本方法 package com.haidai.Map; import java.util.HashMap; import java.ut
HashMap,LinkedHashMap與TreeMap
HashMap: 基於Map介面實現,允許null值,非同步,不保證有序,也不保證不隨時間變化。 在HashMap中有兩個很重要的引數,容量(Capacity)和負載因子(Load factor)。 容量(Capacity)就是bucket的大小,負載因子(Load factor)就是b
HashTable、HashMap、LinkedHashMap、TreeMap之間的區別
Map介面 一:HashTable與HashMap之間的區別 HashTable HashMap
java面試整理(四)—— HashMap、LinkedHashMap、TreeMap、Hashtable、HashSet和ConcurrentHashMap區別
注:本篇博文大部分借鑑與該篇博文系列 知識點總結 HashMap HashMap是基於雜湊表的Map介面的非同步實現, 允許使用null值和null鍵(HashMap最多隻允許一條記錄的鍵為null,允許多條記錄的值為null。)。此類不保證對映的順
JAVA中HashMap和LinkedHashMap以及TreeMap的區別
java為資料結構中的對映定義了一個介面java.util.Map;它有四個實現類,分別是HashMap Hashtable LinkedHashMap 和 TreeMap、Map主要用於儲存健值對、根據鍵得到值、因此不允許鍵重複(重複了覆蓋了),但允許值重複 Hash
LinkedList,LinkedHashMap,LruCache原始碼解析
最近正好在複習資料結構的知識,順帶看了下jdk 1.8中的LinkedList和LinkedHashMap以及android中常用的LruCache的原始碼(內部採用LinkedHashMap實現),以加強自己的理解,下面就分享一下我閱讀原始碼的一些簡單的心得。
深入理解 hash 函式、HashMap、LinkedHashMap、TreeMap
前言 Map 是非常常用的一種資料介面。在java中,提供了成熟的 Map 實現。 圖 1 最主要的實現類有 Hashtable、HashMap、LinkedHashMap和 TreeMap。在 HashTable 的子類中,還有 Properties的實現。Prope
(LinkedHashSet,linkedHashMap)(hashSet, hashMap)(treeSet, treeMap)
比如輸入為 1.3.2 LinkedHashSet: linkedHashMap: 1.3.2 hashSet: hashMap: 2.1.3 無序並且不永恆 treeSet: treeMap: 1.2.3
HashMap原始碼,問map原始碼問題?以及LinkedHashMap,TreeMap不同
HashMap 中的 put 方法。put 時先判斷是否為空,不為空就計算 hash 值,再使用 indexFor()方法計算陣
HashMap、HashTable、LinkedHashMap和TreeMap用法和區別
strong style 取出 能力 順序 ron public ons 保存 Java為數據結構中的映射定義了一個接口java.util.Map,它有四個實現類,分別是HashMap、HashTable、LinkedHashMap和TreeMap。本節實例主要介紹這4中實
JDK類集框架實驗(ArrayList,LinkedList,TreeSet,HashSet,TreeMap,HashMap)
ArrayList import java.util.ArrayList; public class C8_3 { public static void main(String[] args) { //
Java: HashMap、HashTable、LinkedHashMap和TreeMap用法和區別
Java為資料結構中的對映定義了一個介面java.util.Map,它有四個實現類,分別是HashMap、HashTable、LinkedHashMap和TreeMap。本節例項主要介紹這4中例項的用法和區別。 關鍵技術剖析: Map用於儲存鍵值對,根據鍵得到值,因此不允許鍵重複,值可以重複。 l
JDK7,8,JD9的hashmap,hashtable,concurrenthashmap及他們的區別
內容和標題一樣長哦,人家寫了好久的。如無特別指明,內容對應的原始碼是jdk1.7(後面會和1.8對比) 1:hashmap簡介(如下,陣列-連結串列形式) HashMap的儲存結構 圖中,紫色部分即代表雜湊表,也
HashMap,HashTable,ConcurrentHashmap區別和原理
HashTable 底層陣列+連結串列實現,無論key還是value都不能為null,執行緒安全,實現執行緒安全的方式是在修改資料時鎖住整個HashTable,效率低,ConcurrentHashMap做了相關優化 初始size為11,擴容:newsize
一文讀懂JDK7,8,JD9的HashMap,HashTable,ConcurrentHashMap及他們的區別
內容和標題一樣長哦,人家寫了好久的。如無特別指明,內容對應的原始碼是jdk1.7(後面會和1.8對比) 1:hashmap簡介(如下,陣列-連結串列形式) HashMap的儲存結構 圖中,紫色部分即代表雜湊表,也稱為雜湊陣列(預設陣列大小是16,每對
常用物件API(ArrayList,Vector,LinkedList的儲存效能和特性,HashMap和HashTable的區別)
ArrayList,Vector,LinkedList的儲存效能和特性: ArrayList和Vector都是使用陣列的方式來儲存資料,此陣列元 素數大於實際儲存的資料以便增加和插入元素, 它們都允許直接按序 號索引元素, 但是插入元素要涉及陣列元素移動等記憶體操作, 所以
java中的幾種泛型類——HashSet、HashMap、TreeSet、TreeMap,遍歷map,排序,HashTable比較
package test; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.TreeMap; public c
Java的資料結構相關的類實現原理,比如LinkedList,ArrayList,HashMap,TreeMap
HashMap是不是有序的? 不是 hashmap的hashcode()生成規則是: 需要了解equals()和hashcode(); 首先了解,equals和==的區別: 1、基本資料型別比較 ==和Equals都比較兩個值是否相等。相等為tr
HashMap、Hashtable、LinkedHashMap、TreeMap、ConcurrentHashMap之間的區別-yellowcong
這些Map集合在面試中,經常會被問道和考到,所以總結一下,HashMap和Hashtable的區別在於1、多執行緒;2、主鍵是否為空;3、繼承的父類 通過Collections.synchronizedMap()的方法,將Map集合變成執行緒安全的。