Queue(I)
队列接口
-
特点
- 先进先出
-
常用特有方法
-
offer() 入队
queue.offer("one"); queue.offer("two"); queue.offer("three"); System.out.println(queue); // [one, two, three]
-
poll() 出队(移除队列的头)
System.out.println(queue); queue.poll(); System.out.println(queue); // [one, two, three] // [two, three]
-
peek() 出队(不移除队列的头)
System.out.println(queue); queue.peek(); System.out.println(queue); // [one, two, three] // [one, two, three]
-
-
常用实现类
LinkedList
-
子接口
Deque
双端队列,也可以作为栈
-
特点
- 作为双端队列 --> 先进先出
- 作为栈 --> 后进先出
-
常用特有方法
- 双端队列
- offerFirst()
- offerLast()
- pollFirst()
- pollLast()
- 栈 (与Stack类似)
- push() 压栈
- pop() 弹栈(移除栈顶对象)
- 双端队列
-
常用实现类
LinkedList
-