java.util.Deque双端队列

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012326462/article/details/84845056

介绍

java.util.Deque是一种双向线性集合,可以再两端对集合进行插入或者删除操作,所以既可以当队列(FIFO),也可以当栈(LIFO),Deque继承java.util.Queue。英文名介绍:A linear collection that supports element insertion and removal at both ends. The name deque is short for "double ended queue"

方法介绍

  1. void addFirst(E e);

    头部添加一个元素,没有容量会抛出IllegalStateException异常

  2. void addLast(E e);

    尾部添加一个元素,没有容量会抛出IllegalStateException异常

  3. boolean offerFirst(E e);

    头部添加一个元素,没有容量时会返回false

  4. boolean offerLast(E e);

    尾部添加一个元素,没有容量时会返回false

  5. E removeFirst();

    头部移除一个元素,deque为空时会抛出异常NoSuchElementException

  6. E removeLast();

    尾部移除一个元素,deque为空时会抛出异常NoSuchElementException

  7. E pollFirst();

    头部移除一个元素,deque为空时返回null

  8. E pollLast();

    尾部移除一个元素,deque为空时返回null

  9. E getFirst();

    获取一个头部元素,不移除,deque为空时抛出异常NoSuchElementException

  10. E getLast();

    获取一个尾部元素,不移除,deque为空时抛出异常NoSuchElementException

  11. E peekFirst();

    获取一个头部元素,不移除,deque为空时返回null

  12. E peekLast();

    获取一个尾部元素,不移除,deque为空时返回null

  13. boolean removeFirstOccurrence(Object o);

    删除第一个与o相等的元素,删除成功返回true

  14. boolean removeLastOccurrence(Object o);

    删除最后一个与o相等的元素,删除成功返回true

** Queue methods **

  1. boolean add(E e);

    等价于 addLast

  2. boolean offer(E e);

    等价于 offerLast

  3. E remove();

    等价于 removeFirst

  4. E poll();

    等价于pollFirst

  5. E element();

    等价于getFirst

  6. E peek();

    等价于peekFirst

  7. boolean addAll(Collection<? extends E> c);

    相当于每个元素分分别调用offer(E e)

** Stack methods **

  1. void push(E e);

    相当于addFirst

  2. E pop();

    相当于removeFirst

** Collection methods **

  1. boolean remove(Object o);

    相当于 removeFirstOccurrence

  2. boolean contains(Object o);

    是否包含某个元素

  3. int size();

    deque的大小

  4. Iterator<E> iterator();

    The elements will be returned in order from first (head) to last (tail)

  5. Iterator<E> descendingIterator();

    The elements will be returned in order from last (tail) to first (head).

猜你喜欢

转载自blog.csdn.net/u012326462/article/details/84845056
今日推荐