# Java源码分析之LinkedList **Repository Path**: fpfgitmy_admin/java-source-code-linkedlist ## Basic Information - **Project Name**: Java源码分析之LinkedList - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-04-28 - **Last Updated**: 2021-04-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #### LinkedList源码分析 + Node为数据存储的基本单位 + 内部声明了Node类型的first和last属性,默认值为null + Node的定义:体现LinkedList的双向链表(有前一个和后一个数据) ``` private static class Node { E item; //内部类的使用 Node next; // 下一个 Node prev; // 前一个 // 存放数据 前一个、中间数据、下一个 Node(Node prev, E element, Node next) { this.item = element; this.next = next; this.prev = prev; } } ``` ##### add方法 ``` public boolean add(E e) { linkLast(e); return true; } ``` + 当前数据进来,last赋值Node对象,并且创建一个以last为前一个参数、e为数据、null为下一个的新Node对象,如果l是null则证明,当前数据是第一条数据,如果不是null则表明是最后一条数据,每次执行完进行++ ``` void linkLast(E e) { final Node l = last; final Node newNode = new Node<>(l, e, null); last = newNode; if (l == null) first = newNode; else l.next = newNode; size++; modCount++; } ```