java face questions set 2020.1.14

You talk about the collection project is how to use the

  1. When using the set list all the attributes of a class of queries, usually used ArrayList, LinkedList is generally used when additions and deletions operation.
  2. set collection used to re-query. General use is HashSet, if necessary sequence query can use TreeSet.
  3. map set is matched by the key way of information, i.e., information to obtain the current through the additional information, with the information transfer to use map.

ArrayList和LinkedList

  1. ArrayList data structure is implemented based on dynamic array, LinkedList based linked list data structure
  2. For random access and get SET, ArrayList LinkedList superior, because ArrayList be randomly positioned, and to move the pointer LinkedList moved step by step to the node.
  3. For new and delete operations add and remove, LinkedList comparative advantage, only need to modify pointer, and ArrayList data to be moved to fill the deleted object space.
    ArrayList non thread-safe, the initial capacity is 0, the call to add a length becomes 10. After each expansion of 1.5 times before.

ArrayList和Vector

  1. Vector capacity expansion mechanism directly to double
  2. Vector methods are synchronized, thread-safe, it's thread-safe approach is to synchronize all the way plus the modifications. Because the addition of synchronized so performance is weaker than ArrayList.

HashMap

  1. Why talk about it.
    HashMap is a hash table, which is a set memory key-value pair (K / V) of. HashMap Hash algorithm is introduced, the key is mapped into an array index. Use Hash Hash algorithm will produce conflict, HashMap solution is to use a chain address law into position using a linked list stored in the conflict. The list of storage nodes has led to too many nodes look for deterioration in performance on the list. In order to optimize the lookup performance, HashMap in turn transformed into red-black tree list after list longer than 8.

If wrong concept to provide our users pointed out, learn together, if good learning method can also be exchange.

Published 24 original articles · won praise 1 · views 554

Guess you like

Origin blog.csdn.net/qq_45366515/article/details/103965394