【发布时间】:2013-02-27 16:32:16
【问题描述】:
在 RandomAccess 标记接口描述中是这样写的:
* <p>The best algorithms for manipulating random access lists (such as
* <tt>ArrayList</tt>) can produce quadratic behavior when applied to
* sequential access lists (such as <tt>LinkedList</tt>). Generic list
* algorithms are encouraged to check whether the given list is an
* <tt>instanceof</tt> this interface before applying an algorithm that would
* provide poor performance if it were applied to a sequential access list,
* and to alter their behavior if necessary to guarantee acceptable
* performance.
在集合类 synchronisedList 方法中,检查了 RandomAccess,如果成功创建 SynchronizedRandomAccessList 对象,但它们也没有关于算法的详细信息。
public static <T> List<T> synchronizedList(List<T> list) {
return (list instanceof RandomAccess ?
new SynchronizedRandomAccessList<T>(list) :
new SynchronizedList<T>(list));
}
这个算法什么时候应用,在哪里应用(它是本地代码)?
【问题讨论】:
-
synchronizedList创建一个数据结构,它不是真正的算法... -
@OliCharlesworth 是对的,但请参阅文档评论,谈论算法...我在问何时何地应用该算法
-
你指的是什么算法?
-
RandomAccess 用于检查Collections framework 的成员是否正在实现它,以便像Collection 这样具有算法的库可以在顺序数据结构中的随机访问期间获得性能优势。
标签: java algorithm collections synchronize