In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about the role of LinkedList in Java. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
LinkedList implements both List and Deque, which enables it to be used in the same way as ArrayList, which in turn enables it to assume the responsibility of a queue. The internal structure of LinkedList is a two-way linked list, and we mentioned this concept when analyzing ArrayDeque, which is to expand the pointer field of a single linked list and add a pointer previous to the previous element.
AbstractSequentialList
AbstractSequentialList is the parent of LinkedList, inherits from AbstractList, and is an abstract class that provides a skeleton for the chained implementation of sequential tables:
This class provides a skeletal implementation of the List interface to minimize the effort required to implement this interface backed by a "sequential access" data store (such as a linked list). For random access data (such as an array), AbstractList should be used in preference to this class.
Its main purpose is to provide a skeleton that implements the List interface to reduce the amount of work we need to implement chained storage-based implementation classes. AbstractSequentialList does not do many special things, the most important of which is to provide a default implementation of the method and abstract the following methods in order to have a more scenario-appropriate implementation:
Public abstract ListIterator listIterator (int index)
Other implementations take advantage of this listIterator method, which we will no longer look at one by one. Let's analyze the implementation of LinkedList
The structure of LinkedList
The inheritance structure of LinkedList is as follows:
As you can see, LinkedList also implements Cloneable, java.io.Serializable and other methods. Drawing lessons from the experience of ArrayList, we can think of that its Clone is also a shallow clone, and we will not repeat it in the same way in the serialization method.
Construction method and member variable data unit Node
As mentioned in the introduction of linked list structure, its data unit is divided into data domain and pointer domain, which store data and point to the location of the next element respectively, which can be solved by defining an entity class in java.
Private static class Node {E item; / / data Node next; / / next element Node prev; / / previous element Node (Node prev, E element, Node next) {this.item = element; this.next = next; this.prev = prev;}} member variable
There are mainly three LinkedList member variables, and their meaning is clearly visible.
/ / record the length of the current linked list transient int size = 0 position transient Node first;// / first node transient Node last; constructor of the last node
Because the linked list does not have a length problem, it does not involve expansion and other issues, and its constructor is also very concise.
Public LinkedList () {} public LinkedList (Collection
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.