谈一谈Vector类

1.从 Java 2 平台 v1.2 开始,vector类改进为实现 List 接口,成为 Java Collections Framework 的成员。所以vector类有一些遗留的方法。

2.Vector特点:线程安全的,因为很多方法都是同步方法。

3.Oracle官方文档:

  If you need synchronization, a Vector will be slightly faster than an ArrayList synchronized with Collections.synchronizedList. But Vector has loads of legacy operations, so be careful to always manipulate the Vector with the List interface or else you won't be able to replace the implementation at a later time. ----摘自 https://docs.oracle.com/javase/tutorial/collections/implementations/list.html

4.即使要线程安全,通常也不用Vector,因为:

  Vector synchronizes on each individual operation. That's almost never what you want to do. Generally you want to synchronize a whole sequence of operations. you can decorate a collection using the calls such as Collections.synchronizedList.  ---- 摘自 https://stackoverflow.com/questions/1386275/why-is-java-vector-and-stack-class-considered-obsolete-or-deprecated

 

参考资料:

  1)https://docs.oracle.com/javase/tutorial/collections/implementations/list.html

  2)https://www.jianshu.com/p/a20052ac48f1

  3)https://stackoverflow.com/questions/1386275/why-is-java-vector-and-stack-class-considered-obsolete-or-deprecated

  4)https://blog.csdn.net/shecanwin/article/details/70846690

猜你喜欢

转载自www.cnblogs.com/xy-ouyang/p/10474169.html