1. 接口说明

Marker interface used by List implementations to indicate that they support fast (generally constant time) random access. The primary purpose of this interface is to allow generic algorithms to alter their behavior to provide good performance when applied to either random or sequential access lists.

列表(List)实现使用的标记接口,用于指示它们支持快速(通常是恒定时间)随机访问。该接口的主要目的是允许通用(一般的)算法改变其行为,以便在应用于随机或顺序访问列表时提供良好的性能。

The best algorithms for manipulating random access lists (such as ArrayList) can produce quadratic behavior when applied to sequential access lists (such as LinkedList). Generic list algorithms are encouraged to check whether the given list is an instanceof 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.

操纵随机访问的列表最佳的算法(如ArrayList)当应用在顺序访问列表会产生二次行为(如LinkedList)。鼓励(支持)通用(一般的)列表算法在应用算法之前检查给定的列表是否是该接口的实例,如果将算法应用于顺序访问列表,则该算法将提供较差的性能,并在必要时改变他们的行为,以保证可以接受的性能。

It is recognized that the distinction between random and sequential access is often fuzzy. For example, some List implementations provide asymptotically linear access times if they get huge, but constant access times in practice. Such a List implementation should generally implement this interface. As a rule of thumb, a List implementation should implement this interface if, for typical instances of the class,

可以认识到,随机访问和顺序访问之间的区别通常是模糊的。例如,某些 列表实现提供渐进的线性访问时间,如果它们获得极大的访问时间,但实际上是恒定的访问时间。这样的 列表实现通常应该实现此接口。根据经验,如果对于类的典型实例,列表实现应该实现这个接口,

this loop:

这个循环

    for (int i=0, n=list.size(); i < n; i++)
      list.get(i);

runs faster than this loop:

速度快于这个循环
    for (Iterator i=list.iterator(); i.hasNext(); )
      i.next();

可以使用

public class ArrayList<E> extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, java.io.Serializable
public class LinkedList<E> extends AbstractSequentialList<E>
     implements List<E>, Deque<E>, Cloneable, Serializable
测试一下。

Jdk 接口类RandomAccess了解的更多相关文章

  1. Java 通过getbean取出的类为什么要强转为接口类

    这个问题是之前一个同学问我的,这些是我在网上找到的资料,由于我自己也没有完全搞明白,先大概记录一下 首先问题是为什么在bean文件中注入的是实现类,但是通过getBean()取出的时候却必须强制转化为 ...

  2. C++:如何正确的定义一个接口类

    C++中如何定义接口类?首先给接口类下了定义:接口类应该是只提供方法声明,而自身不提供方法定义的抽象类.接口类自身不能实例化,接口类的方法定义/实现只能由接口类的子类来完成. 而对于C++,其接口类一 ...

  3. java基础2.-------interface接口类,实现接口

    1.为什么使用接口,是把功能方法都写在一个类中,在其他需要调用的时候,通过implements实现该接口 2.接口可以继承多个父类接口,在实现接口的时候,实现类实现所有方法 3.在接口类写方法时,自动 ...

  4. PHP中的特殊类,接口类和抽象类(都不能直接实例化)

    接口类不用实例化,需要一一实现接口定义的所有方法.关键字interface implements 接口interface 是一个规定,给人继承用的东西,有点像抽象类在里面定义的方法,却不去实例化,而需 ...

  5. 调用c++接口类

    调用c++接口类 public class CarDeviceDll { /*对dll库进行一些初始化*/ [DllImport("IDI.dll")] public static ...

  6. 无法将类型为“Excel.ApplicationClass”的 COM 对象强制转换为接口类 型“Excel._Application”。此操作失败的原因是对 IID 为“{000208D5 -0000-0000-C000-000000000046}”的接口的 COM 组件调用 QueryInterface 因以下错误而失败: 加载类型库/DLL 时出错。 (异常来 自 HRESULT:

    无法将类型为“Excel.ApplicationClass”的 COM 对象强制转换为接口类 型“Excel._Application”.此操作失败的原因是对 IID 为“{000208D5 -000 ...

  7. 类,抽象基类,接口类三者间的区别与联系(C++)

    结构上的区别: 普通类:数据+方法+实现 抽象类:数据+方法(一定包含虚方法n>=1)+部分方法的实现 接口类:方法(纯虚方法) http://www.cnblogs.com/Tris-wu/p ...

  8. PHP接口类interface的正确使用方法

    对于那些初学PHP语言的人来说,对于PHP的接口类也许了解的还不是很深入,接下来我们就来具体讲述PHP接口类interface的使用方法. 如何正确运用PHP XMLReader解析XML文档 深入解 ...

  9. PHP的接口类(interface)和抽象类(abstract)的区别

    <?php /** * 接口类:interface * 其实他们的作用很简单,当有很多人一起开发一个项目时,可能都会去调用别人写的一些类, * 那你就会问,我怎么知道他的某个功能的实现方法是怎么 ...

随机推荐

  1. MySQL读取Binlog日志常见的3种错误

    1. mysqlbinlog: [ERROR] unknown variable 'default-character-set=utf8mb4' 当我们在my.cnf中添加default-charac ...

  2. 向MIP开源项目提交Issues

    Issues 是 GitHub 管理需求,讨论技术方案的方式,附:官方解释.MIP 是在 GitHub 上的开源项目,也使用 Issues 来做任务管理. 一.Issues 在 MIP 项目中的应用 ...

  3. #Java学习之路——基础阶段二(第二篇)

    我的学习阶段是跟着CZBK黑马的双源课程,学习目标以及博客是为了审查自己的学习情况,毕竟看一遍,敲一遍,和自己归纳总结一遍有着很大的区别,在此期间我会参杂Java疯狂讲义(第四版)里面的内容. 前言: ...

  4. 生产环境中学习Redis

    摘要 看到这篇文章,很有借鉴意义,因此写个读书笔记,不算是翻译.想要深入了解,请看原文http://tech.trivago.com/2017/01/25/learn-redis-the-hard-w ...

  5. mysql error 2005 - Unknown MySQL server host 'localhost'(11001)

    有的时候偶尔会出现这个问题 2005 Unknown MySQL server host 'localhost' (11001),刚开始重启电脑ok了,但是不能每次出现这个问题就重启电脑吧,太麻烦了, ...

  6. Linux命令(精简版)

    1:init 0 关机(root用户可用) 2:exit退出终端 3:who查看登录用户 4:whoami 查看当前用户 5:data 查看当前时间       data  “月日时分年”  修改当前 ...

  7. 机器学习之决策树二-C4.5原理与代码实现

    决策树之系列二—C4.5原理与代码实现 本文系作者原创,转载请注明出处:https://www.cnblogs.com/further-further-further/p/9435712.html I ...

  8. 2.2Bind建立配置文件和实体的映射「深入浅出ASP.NET Core系列」

    希望给你3-5分钟的碎片化学习,可能是坐地铁.等公交,积少成多,水滴石穿,谢谢关注. 新建MVC项目 这次我们没有使用控制台项目,而是使用mvc来测试. 如下图所示,选择空的项目,建完后,记得把项目设 ...

  9. 对称密码——DES加密算法

    前言 本篇博文将介绍对称密码算法中的DES密码的算法原理与代码实现(Java) DES算法原理 DES加密算法是对称加密算法(加密和解密使用同一个密钥)中的一种,DES也是分组密码,以64位为分组对明 ...

  10. 第一册:lesson 121.

    原文:The man in a hat. question:Why didn't Caroline  recognize the customer straight away? I bought tw ...