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

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

 * dratic behavior when applied to
 * sequential access lists (such as arantee acceptable
 * performance.

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

public static 

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

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

public static arableteratorBinarySearch(list,key);
}

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

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.

相关文章

Java中的String是不可变对象 在面向对象及函数编程语言中,不...
String, StringBuffer 和 StringBuilder 可变性 String不可变...
序列化:把对象转换为字节序列的过程称为对象的序列化. 反序...
先说结论,是对象!可以继续往下看 数组是不是对象 什么是对...
为什么浮点数 float 或 double 运算的时候会有精度丢失的风险...
面试题引入 这里引申出一个经典问题,看下面代码 Integer a ...