在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.