java foundation to improve the LinkedList

        This one we introduce LinkedList. LinkedList structure is simple details, please read on.

basic introduction

        According to the instructions in the source code, the LinkedList is a doubly linked list List and Deque interface implementation to achieve all selectable operations, and allows all types of data elements comprises a null.

        It is noteworthy that, LinkedList in, will be based on when the index lookup based on this index distance from the head pointer and the tail pointer of balance, or select Start from scratch or from traversing the top end of the beginning.

        LinkedList not thread-safe, if multiple threads access a synchronized LinkedList and at least one thread to change the structure of this list, then this must be done LinkedList additional locking operations to ensure the security thread. This additional operation may be if this list is encapsulated in an object, can be locked to accomplish that object, if not the kind of object, you can use: List list = Collections.synchronizedList (new LinkedList (...)); to complete the lock function.

        LinkedList returned Iterator is based on the rapid failure mechanisms. About rapid failure mechanism can be seen in this article .

Storage structure

As with previous articles, we'll explore the storage structure by looking at the properties of LinkedList:

He attributes the content very simple, to so few. We briefly explain

  1. size: Actually Needless to say, that is the number of elements stored records.

  2. first: we said, LinkedList is a doubly linked list, and that this is the first head of the doubly linked list of pointers.

  3. last: The last tail pointer is doubly linked list.

Specifically, we now look at the internal nodes Node LinkedList class looks like this:

Very simple, consisting of a stored data item, a predecessor node prev, a successor node next, and now we may clear understanding of the LinkedList storage structure, we use a map to look deeper impression.

Wherein prex head is a null node, which is the first node in FIG, next is the last node is the null node is the last node of FIG.

to sum up

  1. Compared with ArrayList, we have achieved the Collection interface
  2. ArrayList array based, with high query speed, while LinkedList based on a doubly linked list, add or delete a faster pace.
  3. The use of such linked list data structures, no expansion

Reproduced in: https: //juejin.im/post/5cf262dae51d4556db6949b7

Guess you like

Origin blog.csdn.net/weixin_33734785/article/details/91482344