java collections framework for understanding knowledge

HashMap: is the Key-Value Style

The bottom layer is added to the list style array, back to storage arrays + + black tree list

Array is the main, if time itself creates no size is specified, the default size is 16.

Key is obtained corresponding hashCode, using bitwise calculating a key value corresponding to the array table, a circular linked list of the location, using the key value eques method of comparing the linked list, if with the key input of the same value is found, the replacement value the new value value value, if not found, then inserted in the list.

When the capacity of the large threshold value, i.e., the array size * load factor, the required expansion, is expanded to two times the current capacity of the array. The original hash to the array element newly generated by calculating a new hash value (also called the array element per barrel)

When the initialization hashmap capacity when the size of the array is initialized

When converted to a red-black tree chain length of 8, when the bucket conversion element 6 will be less than or equal to the list

HashSet: you do not need to repeat the collection

HashSet HashMap is the underlying structure, inserted into HashSet value, the key value is the hashMap, because, in hashMap key value can not be repeated, it can not be repeated hashset set, because the elements hashMap is disordered, so the value of HashSet is disorderly

ArrayList: an ordered collection can be repeated

ArrayList bottom array is the default size is 10, and the array size is not enough, the array is 1.5 times the current into the expansion capacity. Then moved to the new array element long array. Use Arrays.copyOf (); Method

Whenever you are trying to insert elements in a fixed position, the value of the position is a backward move, delete the value of a position when the value is moved forward one position behind

Since the bottom is an array, the elements can be repeated and Ordered

LinkedList: an ordered set of repeatable

LinkedList way circular linked list, and the bottom is the head node is not stored value, there is no concept of length, not initialized default size

When inserted, the default inserted into the last one, when deleted, the need to remove the need to traverse the same field value

When deleting a fixed position, to determine the size and position of the size / 2, if / 2 is larger than the size, the position from the size / 2 is traversing, if / 2 is smaller than the size, traversing from 0

HashTable way to use synchronize modification, efficiency under

concureentHashMap thread-safe HashMap

volatile int sizeCtl; state control, if the table is less than zero initialization, the thread is blocked, otherwise replace replace cas

  • put () are key requirements can not be empty
  • After two hash, the data is uniformly dispersed, reducing the number of collisions
  • Determine whether the tab has been initialized, then call initTable not initialize operation (single threaded)
  • Position array element i does not exist, directly into
  • If the position i during MOVE operation, that is undergoing capacity expansion operation, multi-threading to help expansion
  • If the position i are elements exist, then the node locked Synchronized, or red-black tree list is determined, is inserted in a corresponding insertion rule
  • get method:
  • The passed key, acquiring the corresponding hash values
  • It is then determined whether the current table array is empty
  • Calculating a position specified key stored in the table
  • The method of red-black tree or list dependent conversion process
  • There is no null is returned
     

 

Published 15 original articles · won praise 0 · Views 1067

Guess you like

Origin blog.csdn.net/ma316110/article/details/85244895