Java, Android Data Structure section

Java Data Structure

  • List

    • List are ordered; thread unsafe; there is length; internal hold modCount record number of modifications

    • ArrayList default length is 10, for expansion (0.5) beyond the length, the maximum length of 31 -8 th power of 2, will exceed the OOM; characteristics: fast search slow pruning

    • LinkedList two-way linked list implemented by internal class Node objects; deletions quick look slow, queries made two points (subscript before the second half) query optimization

    List of entities carrying implement Comparable, Comparator interface allows for fast sorting List

    Collections.synchronizedList (list); it can make thread-safe List

    new ArrayList (new String []) and List.toArray () may be implemented List, Array Huzhuan

    Arrays.asList () returned List is Arrays internal class, it does not provide write operation, it is read-only

  • Map

    • Map Common Features

      Disorderly; thread unsafe;

    • Hashtable

      • Thread-safe (disclosed methods are added to the synchronized)

      • Does not permit null key and null value

      • The default size of 11, a default load factor 0.75

        When the size> * load capacity factor, the capacity will be expanded to 2N +1

      • This class has been eliminated (note not discard), if you do not thread-safe can be used instead of HashMap, if need thread-safe can make use ConcurrentHashMap

    • HashMap

    • Comparison of Hashtable and HashMap

      HashMap thread-safe Hashtable abandoned after a series of specific characteristics and setting the Map data structure of non-thread-safe access to the scene of more efficient

      • HashMap thread-safe; Hashtable thread-safe;

      • HashMap default capacity (16) and expansion capacity are N-th power of 2;. Hashtable default capacity (11) and expansion capacity of the (2N + 1) number of prime design capacity can be reduced key hash collision, but the N 2 power capacity design can be more efficiently acquired key position (Entry array location) in the hash bucket

      • Of key internal HashMap hashCode made of a new set of hash operation rules, so high are also involved in the position calculation, thereby reducing the probability of collisions.

      • HashMap after the collision nodes to implement a linked list, the linked list of nodes in the length of more than 7, the list to the query in order to increase the efficiency of the tree

      • https://www.cnblogs.com/xinzhao/p/5644175.html

    • ConcurrentHashMap

      • Thread-safe, optimized multi-threaded architecture to achieve Map

      • Does not permit null key and null value

      • Other features similar with HashMap

    • LinkedHashMap

      • HashMap subclass, the structure and operation is changed to a linked list, you can ensure orderly

      • accessOrder default fasle, on behalf of intervening sequence; removeEldestEntry override method is true for the modified algorithm for fast implementation lru

    • TreeMap

      • But we can not allow null key null value

      • It may be ordered elements, unordered set (inserted sequence and convenient order consistent)

    Collections.synchronizedMap (map); Map the wire can drive safely.

    Map key needs to have a rewritable non-denatured and equals () and hashCode () method

    Hashtable HashMap and the underlying data structure is an array, the order form and in the form of a combination of one-way linked list, each internal node is Node object

  • Set (part no intentions of writing this)

    Thread unsafe, disorderly and elements can not be repeated

    Be implemented using the underlying map (HashMap & LinkedHashMap), borrow the map key characteristics can not be repeated, is not to achieve repeatability

    Difference HashSet, LinkedHashSet, TreeSet of

    • They can not guarantee the security thread, the underlying implementation does not use a map repetitive (so characteristic in the map), Set can not get the elements using the get (index), it can only be acquired using iterator which:

      • HashSet use HashMap, can not guarantee orderly.

      • LinkedHashSet use LinkedHashMap, you can guarantee the orderly

      • TreeSet use NavigableMap, you may be used to control the order Comparator

    Collections.synchronizedSet (set); Set allows thread-safe

Android data structure

  • SparseArray、SparseBooleanArray、SparseIntArray、SparseLongArray

    • Internal key, value the use of data to achieve, using int key, for Boolean, Int and Long additional processing also eliminates the packing behavior value, improve performance

    • The use of an array of internal compression represents sparse arrays, saving memory

    • Data Access adds binary search process to speed up the processing speed

    • Use append excellent operating performance data is added, it does not recommend the use of put directly

    (Cause binary search) scenarios suitable key may be used to type int and the amount of data within one thousand

  • LongSparseArray

    Use long as the key is no different from other SparseArray; class in packet androidx.collection

  • ArrayMap

    • Internal array implemented; data access binary search process is added

    • Recommended ArrayMap instead of HashMap in one thousand or less the amount of data the situation

  • ArraySet

    Android one pair with ArrayMap is set to achieve

about me

More Android interview senior collection on github above the

Need little friends can click on my  link I get

Very much like to share with everyone and common progress

 Currently a programmer, Android developers not only to share knowledge, but also to share technical people grew up, including personal summary, experience in the workplace, interview experience, you want to make less go a little detour.

Guess you like

Origin www.cnblogs.com/1157760522ch/p/11687155.html