📅  最后修改于: 2020-11-14 06:09:12             🧑  作者: Mango
java.util.ArrayDeque类提供可调整大小的数组并实现Deque接口。以下是关于数组双端队列的要点-
阵列双端队列没有容量限制,因此可以根据需要增长以支持使用。
它们不是线程安全的。在没有外部同步的情况下。
它们不支持多个线程的并发访问。
数组双端队列中禁止使用空元素。
它们比Stack和LinkedList快。
此类及其迭代器实现Collection和Iterator接口的所有可选方法。
以下是java.util.ArrayDeque类的声明-
public class ArrayDeque
extends AbstractCollection
implements Deque, Cloneable, Serializable
在这里
ArrayList list = new ArrayList();
Sr.No. | Constructor & Description |
---|---|
1 |
ArrayDeque() This constructor is used to create an empty array deque with an initial capacity sufficient to hold 16 elements. |
2 |
ArrayDeque(Collection extends E> c) This constructor is used to create a deque containing the elements of the specified collection. |
3 |
ArrayDeque(int numElements) This constructor is used to create an empty array deque with an initial capacity sufficient to hold the specified number of elements. |
Sr.No. | Method & Description |
---|---|
1 | boolean add(E e)
This method inserts the specified element at the end of this deque. |
2 | void addFirst(E e)
This method inserts the specified element at the front of this deque. |
3 | void addLast(E e)
This method inserts the specified element at the end of this deque. |
4 | void clear()
This method removes all of the elements from this deque. |
5 | ArrayDeque This method returns a copy of this deque. |
6 | boolean contains(Object o)
This method returns true if this deque contains the specified element. |
7 | Iterator This method returns an iterator over the elements in this deque in reverse sequential order. |
8 | E element()
This method retrieves, but does not remove, the head of the queue represented by this deque. |
9 | E getFirst()
This method retrieves, but does not remove, the first element of this deque. |
10 | E getLast()
This method retrieves, but does not remove, the last element of this deque. |
11 | boolean isEmpty()
This method returns true if this deque contains no elements. |
12 | Iterator This method returns an iterator over the elements in this deque. |
13 | boolean offer(E e)
This method inserts the specified element at the end of this deque. |
14 | boolean offerFirst(E e)
This method inserts the specified element at the front of this deque. |
15 | boolean offerLast(E e)
This method inserts the specified element at the end of this deque. |
16 | E peek()
This method retrieves, but does not remove, the head of the queue represented by this deque, or returns null if this deque is empty. |
17 | E peekFirst()
This method retrieves, but does not remove, the first element of this deque, or returns null if this deque is empty. |
18 | E peekLast()
This method retrieves, but does not remove, the last element of this deque, or returns null if this deque is empty. |
19 | E poll()
This method retrieves and removes the head of the queue represented by this deque, or returns null if this deque is empty. |
20 | E pollFirst()
This method retrieves and removes the first element of this deque, or returns null if this deque is empty. |
21 | E pollLast()
This method retrieves and removes the last element of this deque, or returns null if this deque is empty. |
22 | E pop()
This method pops an element from the stack represented by this deque. |
23 | void push(E e)
This method pushes an element onto the stack represented by this deque. |
24 | E remove()
This method retrieves and removes the head of the queue represented by this deque. |
25 | boolean remove(Object o)
This method removes a single instance of the specified element from this deque. |
26 | E removeFirst()
This method retrieves and removes the first element of this deque. |
27 | boolean removeFirstOccurrence(Object o)
This method removes the first occurrence of the specified element in this deque. |
28 | E removeLast()
This method retrieves and removes the last element of this deque. |
29 | boolean removeLastOccurrence(Object o)
This method removes the last occurrence of the specified element in this deque. |
30 | int size()
This method returns the number of elements in this deque. |
31 | object[] toArray()
This method returns an array containing all of the elements in this deque in proper sequence. |