Java LinkedList
LinkedList是基于双向链表实现的,先看构造方法和方法
Constructor Summary
Constructors Constructor Description LinkedList()Constructs an empty list.LinkedList(Collection<? extends E> c)Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
Method Summary
All MethodsInstance MethodsConcrete Methods Modifier and Type Method Description voidadd(int index,E element)Inserts the specified element at the specified position in this list.booleanadd(E e)Appends the specified element to the end of this list.booleanaddAll(int index,Collection<? extendsE> c)Inserts all of the elements in the specified collection into this list, starting at the specified position.booleanaddAll(Collection<? extends E> c)Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.voidaddFirst(E e)Inserts the specified element at the beginning of this list.voidaddLast(E e)Appends the specified element to the end of this list.voidclear()Removes all of the elements from this list.Objectclone()Returns a shallow copy of thisLinkedList.booleancontains(Object o)Returnstrueif this list contains the specified element.Iterator<E>descendingIterator()Returns an iterator over the elements in this deque in reverse sequential order.Eelement()Retrieves, but does not remove, the head (first element) of this list.Eget(int index)Returns the element at the specified position in this list.EgetFirst()Returns the first element in this list.EgetLast()Returns the last element in this list.intindexOf(Object o)Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.intlastIndexOf(Object o)Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.ListIterator<E>listIterator(int index)Returns a list-iterator of the elements in this list (in proper sequence), starting at the specified position in the list.booleanoffer(E e)Adds the specified element as the tail (last element) of this list.booleanofferFirst(E e)Inserts the specified element at the front of this list.booleanofferLast(E e)Inserts the specified element at the end of this list.Epeek()Retrieves, but does not remove, the head (first element) of this list.EpeekFirst()Retrieves, but does not remove, the first element of this list, or returnsnullif this list is empty.EpeekLast()Retrieves, but does not remove, the last element of this list, or returnsnullif this list is empty.Epoll()Retrieves and removes the head (first element) of this list.EpollFirst()Retrieves and removes the first element of this list, or returnsnullif this list is empty.EpollLast()Retrieves and removes the last element of this list, or returnsnullif this list is empty.Epop()Pops an element from the stack represented by this list.voidpush(E e)Pushes an element onto the stack represented by this list.Eremove()Retrieves and removes the head (first element) of this list.Eremove(int index)Removes the element at the specified position in this list.booleanremove(Object o)Removes the first occurrence of the specified element from this list, if it is present.EremoveFirst()Removes and returns the first element from this list.booleanremoveFirstOccurrence(Object o)Removes the first occurrence of the specified element in this list (when traversing the list from head to tail).EremoveLast()Removes and returns the last element from this list.booleanremoveLastOccurrence(Object o)Removes the last occurrence of the specified element in this list (when traversing the list from head to tail).Eset(int index,E element)Replaces the element at the specified position in this list with the specified element.intsize()Returns the number of elements in this list.Spliterator<E>spliterator()Creates a late-binding and fail-fastSpliteratorover the elements in this list.Object[]toArray()Returns an array containing all of the elements in this list in proper sequence (from first to last element).<T> T[]toArray(T[] a)Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array
构造方法LinkedList()//创建一个空LinkedList
LinkedList(Coolection<? extends E>)//创建一个有内容的LinkedList,可以将别的LinkedList复制进来(不是引用)
LinkedList增加和删除元素都是常数时间(假设位置已知)
add(int index,E element)向索引位置插入,线性时间
add(E e)默认队尾
addFirst(E e)插入队头
addList(E e)插入队尾
removeFirst(E e)删除队头元素
removeLast(E e)删除队尾元素
LinkedList查询修改元素是线性时间,这点不如ArrayList但是LinkedList的增加和删除是常数时间,不需要移动其他元素的位置。
Java LinkedList的更多相关文章
- java LinkedList(链表)
LinkedList也像ArrayList一样实现了基本的List接口,但是它执行某些操作(在List的中间插入和移除)时比ArrayList更高效,但在随机访问方面却要逊色一些 LinkedList ...
- Java LinkedList add vs push
Java LinkedList add 是加在list尾部. LinkedList push 施加在list头部. 等同于addFirst.
- Java LinkedList【笔记】
Java LinkedList[笔记] LinkedList LinkedList 适用于要求有顺序,并且会按照顺序进行迭代的场景,依赖于底层的链表结构 LinkedList基本结构 LinkedLi ...
- java LinkedList (详解)
Java 链表(LinkedList) 一.链表简介 1.链表 (Linked List) 是一种常见的基础数据结构,是一种线性表,但是链表不会按线性表的顺序存储数据,而是每个节点里存到下一个节点的地 ...
- Java LinkedList 源码剖析
LinkedList同时实现了List接口和Deque接口,也就是说它既可以看作一个顺序容器,又可以看作一个队列(Queue),同时又可以看作一个栈(Stack).这样看来,LinkedList简直就 ...
- java@ LinkedList 学习
package abc.com; import java.util.LinkedList; public class TestLinkedList { static void prt(Object o ...
- JAVA LinkedList和ArrayList的使用及性能分析
第1部分 List概括List的框架图List 是一个接口,它继承于Collection的接口.它代表着有序的队列.AbstractList 是一个抽象类,它继承于AbstractCollection ...
- [Java] LinkedList / Queue - 源代码学习笔记
简单地画了下 LinkedList 的继承关系,如下图.只是画了关注的部分,并不是完整的关系图.本博文涉及的是 Queue, Deque, LinkedList 的源代码阅读笔记.关于 List 接口 ...
- Java LinkedList 源码分析
简介 LinkedList 是一个常用的集合类,用于顺序存储元素. LinkedList 经常和 ArrayList 一起被提及.大部分人应该都知道 ArrayList 内部采用数组保存元素,适合用于 ...
- Java LinkedList特有方法程序小解 && 使用LinkedList 模拟一个堆栈或者队列数据结构。
package Collection; import java.util.LinkedList; /* LinkedList:特有的方法 addFirst()/addLast(); getFirst( ...
随机推荐
- 用bayes公式进行机器学习的经典案例
用bayes公式进行机器学习的经典案例 从本科时候(大约9年前)刚接触Bayes公式,只知道P(A|B)×P(B) = P(AB) = P(B|A)×P(A) 到硕士期间,机器学习课上对P(B|A)P ...
- Oracle12c Client安装出现"[INS-30131]"错误“请确保当前用户具有访问临时位置所需的权限”解决办法之完整版
管理工具>计算机管理>系统工具>共享文件夹>共享 右键单击“共享”>新建共享> 如果出现右键无法出现“新建共享”选项请"控制面板>所有控制面板项&g ...
- Loadrunner:win10下Vuser 运行脚本通过,Controller执行用户并发报错
现象:win7安装LR可以正常使用,将win7升级到win10之后,运行场景之后报错:Error (-81024): LR_VUG: The 'QTWeb' type is not supported ...
- 《锋利的JQuery》中重写超链接与图片提示效果
代码部分: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <met ...
- springMVC数据模型model,modelmap,map,@ModelAttribute的相互关系
结论: a.注解方法中形参为model,modelmap,map一个或几个时,他们指向的引用对象相同即他们的值相同. b.当使用@ModelAttribute注解请求参数时,springmvc自动将该 ...
- 用大白话谈谈XSS与CSRF
这两个关键词也是老生常谈了,但是还总是容易让人忘记与搞混~.XSS与CSRF这两个关键词时常被拉出来一起比较(尤其是面试),我在这里也在写一篇扫盲文,也帮自己整理一下知识脉络. 这篇文章会用尽量“人话 ...
- 使用STM32CubeMX生成RTC工程[闹钟中断2]
在上次使用STM32CubeMX生成RTC工程[闹钟中断]基础上实现周期间隔的闹钟 一些场合需要周期性的闹钟 现在为了方便设置每十秒来一次. 备注: 当然可以直接修改HAL库static HAL_St ...
- C# 类库调试 启动外部程序无法调试
无法调试进程 test.exe [17936] 中的某些代码.请参阅下面的状态信息. IntelliTrace 代码失败(0x80131534). Managed (v4.6.v4.5.v4.0 ...
- BBS--功能4:个人站点页面设计(ORM跨表与分组查询)
查询: 日期归档查询 1 date_format ============date,time,datetime=========== create table t_mul_new(d date,t t ...
- APP-2-Hbuilder开发环境搭建
1.Hbuilder下载 http://www.dcloud.io/hbuilderx.html 2.夜神模拟器下载 https://www.yeshen.com/ 3.chrome浏览器下载 htt ...