• LinkedList


     

    1. package src.com.zhang.likedlist;
    2. import java.util.Iterator;
    3. import java.util.LinkedList;
    4. public class doubleLinkedList {
    5. public static void main(String[] args) {
    6. LinkedList linkedList=new LinkedList<>();//此时linkedlist的firstlast都为null
    7. linkedList.add(1);
    8. linkedList.add(2);
    9. linkedList.add(3);
    10. linkedList.remove();
    11. // remove方法底层源码
    12. // 默认删除读一个节点
    13. // public E remove() {
    14. // return removeFirst();
    15. // }
    16. //removeFirst底层源码
    17. // public E removeFirst() {
    18. // final Node<E> f = first;
    19. // if (f == null)
    20. // throw new NoSuchElementException();
    21. // return unlinkFirst(f);
    22. // }
    23. // private E unlinkFirst(Node<E> f) {
    24. // // assert f == first && f != null;
    25. // final E element = f.item;
    26. // final Node<E> next = f.next;
    27. // f.item = null;
    28. // f.next = null; // help GC
    29. // first = next;
    30. // if (next == null)
    31. // last = null;
    32. // else
    33. // next.prev = null;
    34. // size--;
    35. // modCount++;
    36. // return element;
    37. // }
    38. // add方法底层源码
    39. // public boolean add(E e) {
    40. // linkLast(e);
    41. // return true;
    42. // }
    43. // linkLast底层源码:
    44. // void linkLast(E e) {
    45. // final Node<E> l = last;
    46. // final Node<E> newNode = new Node<>(l, e, null);
    47. // last = newNode;//使last指向newNode节点
    48. // if (l == null)
    49. // first = newNode;
    50. // else
    51. // l.next = newNode;
    52. // size++;
    53. // modCount++;
    54. // }
    55. //修改某个节点
    56. linkedList.set(1,999);
    57. //获取某个节点对象
    58. System.out.println(linkedList.get(0));
    59. //迭代器遍历
    60. Iterator iterator=linkedList.iterator();
    61. while (iterator.hasNext()){
    62. Object next = iterator.next();
    63. System.out.println(next);
    64. }
    65. for (Object o :linkedList) {
    66. System.out.println(o);
    67. }
    68. }
    69. }

  • 相关阅读:
    项目中使用@Transactional需要注意的点
    Codeforces Round #813 (Div. 2)A-E1
    Handsontable JavaScript 12.2 Crack
    智能运维管理系统平台:数字化转型时代的运维先锋
    Spring(一)核心概念
    K8s: 在Pod中使用亲和性调度节点
    休闲娱乐 - 种花记
    Wi-Fi显示无IP分配是什么意思?编程
    六、e2studio VS STM32CubeIDE之代码自动补全
    量化交易全流程(五)
  • 原文地址:https://blog.csdn.net/qq_55278081/article/details/126487379