JDK8源码阅读笔记--------java.util.LinkedList

官方文档:

链表实现list和deque接口,可以存储所有元素,包括null。该类不是同步的,如果多线程访问同一链表,并且至少有一个线程修改了,则必须外部同步。

  List list = Collections.synchronizedList(new LinkedList(...));

1.public E getFirst()、public E getLast()

2.public E removeFirst()、public E removeLast()

3.public void addFirst(E e)、public void addLast(E e)

4.public boolean contains(Object o)

5.public int size()

6.public boolean add(E e)

7.public boolean remove(Object o)

8.public boolean addAll(Collection<? extends E> c)

扫描二维码关注公众号,回复: 4858694 查看本文章

9.clear()

10.public E get(int index)

11.public E set(int index, E element)

12.public void add(int index, E element)

13.public E remove(int index)

14.public int indexOf(Object o)

15.public int lastIndexOf(Object o)

16.public E peek()、public E element()

Retrieves, but does not remove, the head (first element) of this list.

获取第一个元素

区别:peek()如果集合为空则返回null,element()则会报出异常。

17.public E poll()、public E remove()

Retrieves and removes the head (first element) of this list.

拿到第一个元素用时删除掉。

区别:poll()如果为空则返回null,remove()为空则报异常。

18.public E peekLast()

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

19.public E pollLast()

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

20.public void push(E e)

Pushes an element onto the stack represented by this list. In other words, inserts the element at the front of this list.
This method is equivalent to addFirst.

21.public E pop()

Pops an element from the stack represented by this list. In other words, removes and returns the first element of this list.
This method is equivalent to removeFirst().

22.public Object[] toArray()

猜你喜欢

转载自blog.csdn.net/weixin_39035120/article/details/84587419