集合框架(五)

一、继承关系

AbstractList<-Vector<-Stack

二、Vector

下面这段话来自Java 8的说明文档:

As of the Java 2 platform v1.2, this class was retrofitted to implement the List interface, making it a     member of the Java Collections Framework. Unlike the new collection implementations, Vector is synchronized.     If a thread-safe implementation is not needed, it is recommended to use ArrayList in place of Vector. 

Vector中List的实现方式和ArrayList基本一样,不过Vector是同步的。

三、Statck

下面这段话来自Java 8的说明文档:

The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with five operations     that allow a vector to be treated as a stack. The usual push and pop operations are provided, as well as a method     to peek at the top item on the stack, a method to test for whether the stack is empty, and a method to search     the stack for an item and discover how far it is from the top.

    A more complete and consistent set of LIFO stack operations is provided by the Deque interface and its implementations,     which should be used in preference to this class. For example:

  Deque<Integer> stack = new ArrayDeque<Integer>();  

Stack继承了Vector,并提供了一些自己的方法,实现了List的后进先出的队列。Deque接口和其实现者为"后进先出"队列提供了提供了 更多的操作

四、总结

Vector和Stack都可以看做是Java1.2前的遗留产物,而且都是同步的(线程暂时不是很懂),List的实现一般使用ArrayList(快速随机访问) 或LinkedList(快速插入或删除操作)。

posted @ 2016-07-26 09:10  DeadGhost  阅读(116)  评论(0编辑  收藏  举报