当前位置:网站首页>How is LinkedList added?
How is LinkedList added?
2022-07-02 21:28:00 【java. lang.utils】
Problem description :
1,LinkedList When you do the initialization /** * Constructs an empty list. */
public LinkedList() {
}
2,add Method /** * Appends the specified element to the end of this list. * * <p>This method is equivalent to {@link #addLast}. * * @param e element to be appended to this list * @return {@code true} (as specified by {@link Collection#add}) */
public boolean add(E e) {
linkLast(e);
return true;
}
3, Go to linkLast(e); Method down tracking , The current is the core method of adding /** * Links e as last element. */
void linkLast(E e) {
/* * The first time I added it ,last Is a currently defined Node<E> Object variables * //transient Node<E> last; */
final Node<E> l = last;
/* * Before we create a new Node When the object ,Node In the construction method * The first value is :prev Point to the previous object * Second value :item Currently added element * Third values :next Point to the next object */
final Node<E> newNode = new Node<>(l, e, null);
// After creation Assign to current last
last = newNode;
// Judge l Is it equal to null, so l Namely last The assignment of , In the first addition
// last Namely null therefore l The variable of is null
if (l == null) // Meet the conditions
first = newNode;// Assign a value to first
else
l.next = newNode;
size++;// Index plus
modCount++; // The number of modifications is increased
}
4, This is the result of the first addition 
5, When making the second addition
/** * Links e as last element. */
void linkLast(E e) {
/* * The second time you add ,last It was the last one before Node object */
final Node<E> l = last;
/* * Before we create a new Node When the object ,Node In the construction method * The first value is :prev Point to the previous object , So , When we create the second object * Now this prev Will point to the previous * Second value :item Currently added element * Third values :next Point to the next object */
final Node<E> newNode = new Node<>(l, e, null);
// After creation Assign to current last the last one
last = newNode;
// Judge l Is it equal to null, here l It's the last one Node object
// l It's not equal to null
if (l == null) // Not meeting the conditions
first = newNode;
else
// Let the last Node Of next Point to the newly created node
l.next = newNode;
size++;// Index plus
modCount++; // The number of modifications is increased
}
6, The schematic diagram added for the second time 
7, From this, we can infer , Every time you add a new node , Nodes are appended later , New node's prev Will point to the previous node , The previous node will point to the current new node
8,Node The node is the current static inner class
private static class Node<E> {
E item;
Node<E> next;
Node<E> prev;
Node(Node<E> prev, E element, Node<E> next) {
this.item = element;
this.next = next;
this.prev = prev;
}
}
边栏推荐
- Construction and maintenance of business websites [8]
- Don't you want to have a face-to-face communication with cloud native and open source experts? (including benefits
- Research Report on market supply and demand and strategy of China's atomic spectrometer industry
- China microporous membrane filtration market trend report, technological innovation and market forecast
- [fluent] dart generic (generic class | generic method | generic with specific type constraints)
- [shutter] statefulwidget component (floatingactionbutton component | refreshindicator component)
- Redis sentinel cluster working principle and architecture deployment # yyds dry goods inventory #
- What are the preferential account opening policies of securities companies now? Is it actually safe to open an account online?
- Talk about macromolecule coding theory and Lao Wang's fallacy from the perspective of evolution theory
- Go cache of go cache series
猜你喜欢

rwctf2022_ QLaaS
![[871. Minimum refueling times]](/img/5f/75e717d1fc9d1c5f9e1d8f59dda38c.png)
[871. Minimum refueling times]

Go language learning summary (5) -- Summary of go learning notes

Highly qualified SQL writing: compare lines. Don't ask why. Asking is highly qualified..

Web3js method to obtain account information and balance

Hot backup routing protocol (HSRP)

Customized Huawei hg8546m restores Huawei's original interface

26 FPS video super-resolution model DAP! Output 720p Video Online

5 environment construction spark on yarn

Volvo's first MPV is exposed! Comfortable and safe, equipped with 2.0T plug-in mixing system, it is worth first-class
随机推荐
[shutter] the shutter plug-in is used in the shutter project (shutter plug-in management platform | search shutter plug-in | install shutter plug-in | use shutter plug-in)
Internet Explorer ignores cookies on some domains (cannot read or set cookies)
qwb2018_ core kernel_ rop
Common routines of compressed packets in CTF
[fluent] dart generic (generic class | generic method | generic with specific type constraints)
This team with billions of data access and open source dreams is waiting for you to join
Who do you want to open a stock account? Is it safe to open a mobile account?
Investment strategy analysis of China's electronic information manufacturing industry and forecast report on the demand outlook of the 14th five year plan 2022-2028 Edition
[dynamic planning] p1220: interval DP: turn off the street lights
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of voltage source converters in the global market in 2022
Research Report on crude oil tanker industry - market status analysis and development prospect forecast
AMD's largest transaction ever, the successful acquisition of Xilinx with us $35billion
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of precoated metallic coatings in the global market in 2022
Go cache of go cache series
Accounting regulations and professional ethics [16]
想请教一下,究竟有哪些劵商推荐?手机开户是安全么?
Happy Lantern Festival! Tengyuanhu made you a bowl of hot dumplings!
Write the content into the picture with type or echo and view it with WinHex
Download vagrant box file locally from Atlas and configuring it
Cloud computing technology [1]