Java 集合框架(Deque 接口)

2018-11-25  本文已影响0人  6ea566508d0d

Deque 接口简介

对于 Deque 接口,Java的官方文档这样提到:

Usually pronounced as deck, a deque is a double-ended-queue. A double-ended-queue is a linear collection of elements that supports the insertion and removal of elements at both end points. The Deque interface is a richer abstract data type than both Stack and Queue because it implements both stacks and queues at the same time. The Deque interface, defines methods to access the elements at both ends of the Deque instance. Methods are provided to insert, remove, and examine the elements. Predefined classes like ArrayDeque and LinkedList implement the Deque interface.
Note that the Deque interface can be used both as last-in-first-out stacks and first-in-first-out queues.

简单点来说就是:

Deque 接口相关操作

Deque 接口的方法和 Queue 接口类似,每种方法也有两种形式:

Type of Operation First Element (Beginning of the Deque instance) Last Element (End of the Deque instance)
Insert addFirst(e)
offerFirst(e)
addLast(e)
offerLast(e)
Remove removeFirst()
pollFirst()
removeLast()
pollLast()
Examine getFirst()
peekFirst()
getLast()
peekLast()

这里也不在多累述,大概就是这样:

上一篇 下一篇

猜你喜欢

热点阅读