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
    void add​(int index,E element)
    Inserts the specified element at the specified position in this list.
    boolean add​(E e)
    Appends the specified element to the end of this list.
    boolean addAll​(int index,Collection<? extendsE> c)
    Inserts all of the elements in the specified collection into this list, starting at the specified position.
    boolean addAll​(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.
    void addFirst​(E e)
    Inserts the specified element at the beginning of this list.
    void addLast​(E e)
    Appends the specified element to the end of this list.
    void clear()
    Removes all of the elements from this list.
    Object clone()
    Returns a shallow copy of this LinkedList.
    boolean contains​(Object o)
    Returns true if this list contains the specified element.
    Iterator<E> descendingIterator()
    Returns an iterator over the elements in this deque in reverse sequential order.
    E element()
    Retrieves, but does not remove, the head (first element) of this list.
    E get​(int index)
    Returns the element at the specified position in this list.
    E getFirst()
    Returns the first element in this list.
    E getLast()
    Returns the last element in this list.
    int indexOf​(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.
    int lastIndexOf​(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.
    boolean offer​(E e)
    Adds the specified element as the tail (last element) of this list.
    boolean offerFirst​(E e)
    Inserts the specified element at the front of this list.
    boolean offerLast​(E e)
    Inserts the specified element at the end of this list.
    E peek()
    Retrieves, but does not remove, the head (first element) of this list.
    E peekFirst()
    Retrieves, but does not remove, the first element of this list, or returns null if this list is empty.
    E peekLast()
    Retrieves, but does not remove, the last element of this list, or returns null if this list is empty.
    E poll()
    Retrieves and removes the head (first element) of this list.
    E pollFirst()
    Retrieves and removes the first element of this list, or returns null if this list is empty.
    E pollLast()
    Retrieves and removes the last element of this list, or returns null if this list is empty.
    E pop()
    Pops an element from the stack represented by this list.
    void push​(E e)
    Pushes an element onto the stack represented by this list.
    E remove()
    Retrieves and removes the head (first element) of this list.
    E remove​(int index)
    Removes the element at the specified position in this list.
    boolean remove​(Object o)
    Removes the first occurrence of the specified element from this list, if it is present.
    E removeFirst()
    Removes and returns the first element from this list.
    boolean removeFirstOccurrence​(Object o)
    Removes the first occurrence of the specified element in this list (when traversing the list from head to tail).
    E removeLast()
    Removes and returns the last element from this list.
    boolean removeLastOccurrence​(Object o)
    Removes the last occurrence of the specified element in this list (when traversing the list from head to tail).
    E set​(int index,E element)
    Replaces the element at the specified position in this list with the specified element.
    int size()
    Returns the number of elements in this list.
    Spliterator<E> spliterator()
    Creates a late-binding and fail-fast Spliterator over 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的更多相关文章

  1. java LinkedList(链表)

    LinkedList也像ArrayList一样实现了基本的List接口,但是它执行某些操作(在List的中间插入和移除)时比ArrayList更高效,但在随机访问方面却要逊色一些 LinkedList ...

  2. Java LinkedList add vs push

    Java LinkedList add 是加在list尾部. LinkedList push 施加在list头部. 等同于addFirst.

  3. Java LinkedList【笔记】

    Java LinkedList[笔记] LinkedList LinkedList 适用于要求有顺序,并且会按照顺序进行迭代的场景,依赖于底层的链表结构 LinkedList基本结构 LinkedLi ...

  4. java LinkedList (详解)

    Java 链表(LinkedList) 一.链表简介 1.链表 (Linked List) 是一种常见的基础数据结构,是一种线性表,但是链表不会按线性表的顺序存储数据,而是每个节点里存到下一个节点的地 ...

  5. Java LinkedList 源码剖析

    LinkedList同时实现了List接口和Deque接口,也就是说它既可以看作一个顺序容器,又可以看作一个队列(Queue),同时又可以看作一个栈(Stack).这样看来,LinkedList简直就 ...

  6. java@ LinkedList 学习

    package abc.com; import java.util.LinkedList; public class TestLinkedList { static void prt(Object o ...

  7. JAVA LinkedList和ArrayList的使用及性能分析

    第1部分 List概括List的框架图List 是一个接口,它继承于Collection的接口.它代表着有序的队列.AbstractList 是一个抽象类,它继承于AbstractCollection ...

  8. [Java] LinkedList / Queue - 源代码学习笔记

    简单地画了下 LinkedList 的继承关系,如下图.只是画了关注的部分,并不是完整的关系图.本博文涉及的是 Queue, Deque, LinkedList 的源代码阅读笔记.关于 List 接口 ...

  9. Java LinkedList 源码分析

    简介 LinkedList 是一个常用的集合类,用于顺序存储元素. LinkedList 经常和 ArrayList 一起被提及.大部分人应该都知道 ArrayList 内部采用数组保存元素,适合用于 ...

  10. Java LinkedList特有方法程序小解 && 使用LinkedList 模拟一个堆栈或者队列数据结构。

    package Collection; import java.util.LinkedList; /* LinkedList:特有的方法 addFirst()/addLast(); getFirst( ...

随机推荐

  1. MYSQL 存储 while 统计每个表

    群里一朋友,有一需求就是获取数据库每个表的总计(条数)思路:动态传入表名, count(1) -- 1.执行这句.获取所有表名 as num ) b where t.table_schema='tes ...

  2. 笔记:js疑难复习

    apply 和 call的区别 call 和 apply 的区别只在于这两个函数接受的参数形式不同 var Person = function(name,age){ this.name = name; ...

  3. 30.纯 CSS 创作一个晃动的公告板

    原文地址:https://segmentfault.com/a/1190000014983030 感想: 绝对定位+动画 HTML代码: <div class="signboard&q ...

  4. python学习笔记_week16

    note 作业问题: 1.写页面觉得丑(布局) float,clear:both,margin,padding,position:left...网上找模板:HTML模板,BoostStrap 2.背景 ...

  5. ubuntu 系统分区

    参考:https://blog.csdn.net/kudou1994/article/details/80913059

  6. kubernetes下安装mysql

    参考文档:https://blog.csdn.net/sealir/article/details/81177747 注:有mysql安装在k8s集群内,集群外且通过k8s service endpo ...

  7. 4.高级js--(面向对象js)_2

    1.创建对象的三种方式: l第一种构造法:new  Object var a = new Object(); a.x = 1, a.y = 2; l第二种构造法:对象直接量 var b = { x : ...

  8. node.js 爬虫动态代理ip

    参考文章: https://andyliwr.github.io/2017/12/05/nodejs_spider_ip/ https://segmentfault.com/q/10100000081 ...

  9. c++builder 6 [Linker Fatal error] Unable to open file 'PROXIES.OBJ'

    c++builder 6 [Linker Fatal error] Unable to open file 'PROXIES.OBJ' http://blog.csdn.net/cb168/artic ...

  10. Yum安装MySQL以及相关目录路径和修改目录

    有些时候,为了方便,有些同学喜欢通过yum的方式安装MySQL,没有设置统一的文件目录以及软件目录,那么就会为后续的维护工作带来很大的麻烦! 下面就简单介绍一下yum安装MySQL的步骤以及这类安装下 ...