📜  Java.util.LinkedList类

📅  最后修改于: 2020-11-14 06:19:14             🧑  作者: Mango


介绍

我们可以期望java.util.LinkedList类操作执行双向链接列表。索引到列表中的操作将从开头或结尾遍历列表,以更接近指定索引的位置为准。

类声明

以下是java.util.LinkedList类的声明-

public class LinkedList
   extends AbstractSequentialList
   implements List, Deque, Cloneable, Serializable

参量

以下是java.util.LinkedList类的参数-

E-这是此集合中包含的元素的类型。

领域

从类java.util.AbstractList继承的字段。

类的构造函数

Sr.No. Constructor & Description
1

LinkedList()

This constructs constructs an empty list.

2

LinkedList(Collection c)

This constructs a list containing the elements of the specified collection, in the order they are returned by the collection’s iterator.

类方法

Sr.No. Method & Description
1 boolean add(E e)

This method appends the specified element to the end of this list.

2 void add(int index, E element)

This method inserts the specified element at the specified position in this list.

3 boolean addAll(Collection c)

This method 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.

4 boolean addAll(int index, Collection c)

This method inserts all of the elements in the specified collection into this list, starting at the specified position.

5 void addFirst(E e)

This method returns inserts the specified element at the beginning of this list..

6 void addLast(E e)

This method returns appends the specified element to the end of this list.

7 void clear()

This method removes all of the elements from this list.

8 Object clone()

This method returns returns a shallow copy of this LinkedList.

9 boolean contains(Object o)

This method returns true if this list contains the specified element.

10 Iterator descendingIterator()

This method returns an iterator over the elements in this deque in reverse sequential order.

11 E element()

This method retrieves, but does not remove, the head (first element) of this list.

12 E get(int index)

This method returns the element at the specified position in this list.

13 E getFirst()

This method returns the first element in this list.

14 E getLast()

This method returns the last element in this list.

15 int indexOf(Object o)

This method returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

16 int lastIndexOf(Object o)

This method returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.

17 ListIterator listIterator(int index)

This method returns a list-iterator of the elements in this list (in proper sequence), starting at the specified position in the list.

18 boolean offer(E e)

This method adds the specified element as the tail (last element) of this list.

19 boolean offerFirst(E e)

This method inserts the specified element at the front of this list.

20 boolean offerLast(E e)

This method inserts the specified element at the end of this list.

21 E peek()

This method retrieves, but does not remove, the head (first element) of this list.

22 E peekFirst()

This method retrieves, but does not remove, the first element of this list, or returns null if this list is empty.

23 E peekLast()

This method retrieves, but does not remove, the last element of this list, or returns null if this list is empty.

24 E poll()

This method retrieves and removes the head (first element) of this list.

26 E pollFirst()

This method retrieves and removes the first element of this list, or returns null if this list is empty.

27 E pollLast()

This method retrieves and removes the last element of this list, or returns null if this list is empty.

28 E pop()

This method pops an element from the stack represented by this list.

29 void push(E e)

This method pushes an element onto the stack represented by this list.

30 E remove()

This method retrieves and removes the head (first element) of this list.

31 E remove(int index)

This method removes the element at the specified position in this list.

32 boolean remove(Object o)

This method removes the first occurrence of the specified element from this list, if it is present.

33 E removeFirst()

This method removes and returns the first element from this list.

34 boolean removeFirstOccurrence(Object o)

This method removes the first occurrence of the specified element in this list (when traversing the list from head to tail).

35 E removeLast()

This method removes and returns the last element from this list.

36 boolean removeLastOccurrence(Object o)

This method removes the last occurrence of the specified element in this list (when traversing the list from head to tail).

37 E set(int index, E element)

This method replaces the element at the specified position in this list with the specified element.

38 int size()

This method returns the number of elements in this list.

39 Object[] toArray()

This method returns an array containing all of the elements in this list in proper sequence (from first to last element).

40 T[] toArray(T[] a)

This method 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.

方法继承

此类从以下类继承方法-

  • java.util.AbstractSequentialList
  • java.util.AbstractList
  • java.util.AbstractCollection
  • java.util.Object
  • java.util.List
  • java.util.Deque