Skip to content

Latest commit

 

History

History
21 lines (12 loc) · 821 Bytes

Java集合-Stack.md

File metadata and controls

21 lines (12 loc) · 821 Bytes

Java集合 - Stack

Stack继承于VectorVector则是实现了List接口,所以Stack本质上也是一个List

Vector

Vector的存储方式也和ArrayList一样,使用数组进行存储。

protected Object[] elementData;   //存储数据的数组

Vector中大部分对数据操作的方法都有synchronized修饰符进行修饰,所以Vector是一个线程安全的容器。

Stack

Stack则很简单,除了父类的一些方法之外,它还提供了一些它作为栈的一些操作,例如:push(E):Epop():Epeek():E等等。

而且这些方法都是调用父类方法进行实现的,所以,这些方法都是线程安全的。

PS: peek():E的作用是:Looks at the object at the top of this stack without removing it from the stack.