在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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。