Map

HashMap

getcontainsKeynext
o(1)o(1)o(h/n)
  • Map key to array index to get complexity to O(1) (constant time).
  • resize when table size >= threshold (= table size * load factor). resize = 2*original table size (is always power of 2) and hashed location is not null
  • internal structure is array. each element is a linked entry.
  • modcount to prevent concurrentmodification

LinkedHashMap

getcontainsKeynext
o(1)o(1)o(1)

- extends from HashMap. HashMap has some methods reserved for subclassses, like init, recordAccess
- LinkedHashMap entry extends HashMap entry and adds two more references to entries before it and after it. thus double-linked list
- can be used as LRU list because it can be constructed with access order
- iteration is faster than hashmap because nodes are linked


IdentityHashMap

getcontainsKeynextcomment
o(1)o(1)o(h/n)save key to table[i] and value to table[i+1]. so table size is twice as capacity

- comparing key only by reference id, not equals method
- if there is hash conflict, just rehash by forwarding 2 in table index


WeakHashMap

getcontainsKeynextcomment
o(1)o(1)o(h/n)hash table underlying. entry in table extends from WeakReference. Entry is constructed with a reference queue which holds invalid references (entries) after GC. WeakHashMap then queries the queue for invalid references and removes them from the map. Be noted the removal goes silently.

EnumMap

getcontainsKeynextcomment
o(1)o(1)o(1)use array underlying. the type of key must be enum and specified when construct

TreeMap

getcontainsKeynextcomment
o(log(n))o(log(n))o(log(n))red-black tree underlying, some tree fixes after adding or deleting

ConcurrentHashMap

getcontainsKeynextcomment
o(1)o(1)o(h/n), h is hashtable capacityconsisted of many segments. each segment has its own lock. be careful its size() and containsValue() method since they may lock entire hashmap
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值