Queue的使用

Queue

FIFO(First-in,First-out)
Queue在并发编程中十分重要。
LinkedList有支持Queue行为的方法,它实现了Queue接口,所以LinkedList可以作为Queue实现。

方法

  • offer():在Queue尾插入元素,如果插入失败返回false;
  • peek():返回Queue头元素(不删除),如果没有返回null;
  • element():返回Queue头元素(不删除),如果没有抛出NoSuchElementException()异常;
  • poll():删除并返回头元素,如果没有返回null;
  • remove():删除并返回头元素,如果没有抛出NoSuchElementException()异常;

猜你喜欢

转载自blog.csdn.net/Growing_way/article/details/83006618
今日推荐