【发布时间】:2015-05-28 13:11:35
【问题描述】:
我从来没有愉快地使用下面的代码,现在我偶然发现了一个作业,我想在其中争论哪些是最常用的,以及为什么。
我们有两个例子,
public Vector<Integer> sort(Vector<Integer> integers) { ... }
public Collection<Integer> sort(Collection<Integer> integers) {}
本质上,我们要争论这两个示例中哪一个是对事物进行排序的最佳解决方案。这两个中哪一个用得最多,为什么?
【问题讨论】:
-
矢量已过时。使用集合
-
@aTON 我认为您应该考虑答案,而不是在 stackoverflow 上提问。
-
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的API文档如是说。 (这应该是您真正的第一个呼叫端口。)我个人会补充说,即使需要线程安全的实现,您也应该避免使用Vector。 -
Vector 使用同步,这在大多数情况下是不需要的,并且会影响性能
标签: java sorting vector collections