栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

LinkedList源码(remove)解析:

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

LinkedList源码(remove)解析:

  1. import  java.util.*;
  2. public  class  LinkedListRemove  {
  3.      public  static  void  main (String[] args)  {
  4.         LinkedList  list  =  new  LinkedList();
  5.          list .add( 1 );
  6.          list .add( 2 );
  7.          list .add( 3 );
  8.          list .remove(); //默认删除的是第1个元素
  9.         System.out.println( list );  //输出结果为:  [2, 3]
  10.         
  11.     }
  12. }
                // unlinkFirst()方法详解
  1.     private E unlinkFirst(Node f) {
  2.     //  assert f == first && f != null;
  3.      1.取出item 至 element
  4.     final E element = f.item;
  5.      2.让 next 指向 f. next
  6.     final LinkedList.Node  next = f. next;
  7.      3.将f.item , f. next 置空
  8.     f.item = null;
  9.     f. next = null; // help GC
  10.      4.让first指向 next
  11.     first =  next;
  12.      5.此时的 next不为null,所以执行的是 else中的语句
  13.      if ( next == null)
  14.     last = null;
  15.      else
  16.     将 next.prev置空,此时的f结点就会被虚拟机回收
  17.      next.prev = null;
  18.     size --;
  19.     modCount++;
  20.      return element;
  21. }

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/963547.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号