PriorityQueue
优先级队列使用堆来实现。默认是小根堆。
关键属性:
// 默认容量 private static final int DEFAULT_INITIAL_CAPACITY = 11; // 存储元素的地方 transient Object[] queue; // non-private to simplify nested class access // 元素个数 private int size = 0; // 比较器 private final Comparator<? super E> comparator; // 修改次数 transient int modCount = 0; // non-private to simplify nested class access
几个方法的区别:
remove()和poll()出队,队首元素如果为空remove()抛出异常,poll()返回null
获取队首元素,队首元素如果为空element()抛出异常,peek()返回null
参考:
本文来自博客园,作者:LeeJuly,转载请注明原文链接:https://www.cnblogs.com/peterleee/p/11000740.html

浙公网安备 33010602011771号