栈和队列

本文探讨了Vector如何作为线程安全Stack的基础,以及ArrayQueue如何实现Queue接口。重点介绍了Vector的Synchronized特性,以及push、pop、peek等操作在并发环境中的表现。同时,我们对比了offer、poll和peek方法在Queue中的作用。
摘要由CSDN通过智能技术生成

Stack 继承 Vector, Vector是线程安全的,每个方法都是 Synchronized关键字。 

方法:
push Pushes an item onto the top of this stack
pop Removes the object at the top of this stack and returns that object as the value of this function.
peek Looks at the object at the top of this stack without removing it from the stack.

Queue 接口, ArrayQueue 实现Queue 

方法:

add
offer
poll Retrieves and removes the head of this queue,or returns {@code null} if this queue is empty.
element Retrieves, but does not remove, the head of this queue. This method differs from {@link #peek peek} only in that it throws an exception if this queue is empty.
peek Retrieves, but does not remove, the head of this queue,or returns {@code null} if this queue is empty.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>