On the Map collection

Map interface, hashMap, balanced binary tree

Map Interface

  • Map provides a mapping relationship, which is the key element of (key-value) in the form of storage can be achieved quickly find value in accordance with key
  • Map key-value pairs object instance is present in the form of Entry type
  • Construction (key value) is not repeated, the value may be repeated value, a value and the value can be formed many key value corresponding relationship, each built up can only be mapped to a value.
  • Map generic support, such as in the form: Map <K, V>

hashMap

  • HashMap is based arrays to implement hash table, like the memory array, index like array of memory addresses;
  • Each record is a HashMap Entry <K, V> objects, is stored in the array objects;
  • HashMap hash function calculated hashCode + = calculated array index;
  • HashMap resolve the conflict: a chain address law, each Entry object has a reference point to the next Entry next to the list;
  • HashMap loading factor: 0.75 by default;

HashMap basically like this:

Balanced binary tree

平衡二叉树又名红黑树,是有序二叉树的一种。具有有序二叉树的所有特点,其任意一分支长度不会超过另一支的二倍。
  • Each node is black, not red
  • Root is always black
  • If the node is red, then its child nodes must be black (not necessarily vice versa), (i.e. there are not two consecutive red nodes on all paths from the root to each leaf)
  • Each path from the root node to a leaf node or a blank node, must contain the same number of black nodes (i.e., the same black height)

Reference links

Guess you like

Origin www.cnblogs.com/shaoyu/p/12035538.html