9k9ecw
Last Updated: February 25, 2016
·
796
· orhanobut
62009 433414993266 4621115 n

HashMap, LinkedHashMap, TreeMap, WeakHashMap

<h4>HashMap</h4>

  • Implements Map interface
  • No order guaranteed, order can be changed even when a new element added
  • get, put, remove, contains complexity is O(1)
  • null key and values are allowed
  • Implementation is buckets

<h4>LinkedHashMap</h4>

  • Same as HashMap but the difference is it keeps elements in insert order.
  • Implementation is doubly linked list
  • put,remove complexity is O(1)

<h4>WeakHashMap</h4>
<ul>
<li>Keys of the map stored in weakreference. By doing this, key-value pairs can be dropped in dynamically when the only reference is from weakreference. </li>
<li>When the system needs more resource, those entries will be dropped</li>
</ul>

<h4>TreeMap</h4>

  • Implements Map, SortedMap and NavigableMap
  • Sorted based on keys
  • get,put,remove, contains complexity is O(log(n))
  • only values can be null
  • Implementation is red-black tree
Say Thanks
Respond