小白学Java:奇怪的RandomAccess
目录 小白学Java:奇怪的RandomAccess RandomAccess是个啥 forLoop与Iterator的区别 判断是否为RandomAccess 小白学Java:奇怪的RandomAccess 我们之前在分析那三个集合源码的时候,曾经说到:ArrayList和Vector继承了 RandomAccess 接口,但是LinkedList并没有,我们还知道继承了这个接口,就意味着其中元素支持 快速随机访问(fast random access) 。 RandomAccess是个啥 出于好奇,我特意去查看了RandomAccess的官方文档,让我觉得异常惊讶的是!这个接口中啥也没有!是真的奇怪!(事实上和它类似的还有 Cloneable 和 java.io.Serializable ,这俩之后会探讨)只留下一串冰冷的英文。 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