java – 何时应用操作随机访问列表的算法?

在RandomAccess标记接口描述中写入:

 * 

在集合类synchronisedList方法中,检查RandomAccess&如果成功创建了SynchronizedRandomAccessList对象,但它们也没有关于算法的细节.

public static 

该算法何时适用?何处(是本机代码)?

最佳答案
其中一个例子是Collections.binarySearch:

public static 

这里,不同的二进制搜索算法实现用于随机访问和顺序访问列表.代码是一个实现细节,但在此区分列表是合理的.

documenation for Collections.binarySearch中所述:

This method runs in log(n) time for a “random access” list (which provides near-constant-time positional access). If the specified list does not implement the RandomAccess interface and is large,this method will do an iterator-based binary search that performs O(n) link traversals and O(log n) element comparisons.

相关文章

摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠...
摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠...
今天犯了个错:“接口变动,伤筋动骨,除非你确定只有你一个...
Writer :BYSocket(泥沙砖瓦浆木匠)微 博:BYSocket豆 瓣:...
本文目录 线程与多线程 线程的运行与创建 线程的状态 1 线程...