遇到一个巨无语的bug,也不是bug,是我傻

65 阅读1分钟
public class TT {
    public static void main(String[] args) {
        PriorityBlockingQueue<Integer> pbq= new PriorityBlockingQueue<>(5);
        pbq.offer(68);
        pbq.offer(34);
        pbq.offer(40);
        pbq.offer(31);
        pbq.offer(22);
        System.out.print(pbq.size()+"pbq.size()");
        for (int i = 0; i < pbq.size(); i++) {
            System.out.print(pbq.poll()+"  ");
        }


    }
}

这段代码老是不能全部输出队列里的元素 我都以为jdk出bug了 再三检查下,才发现poll会导致size-1