- 浏览: 200505 次
- 性别:
- 来自: 哈尔滨
文章分类
- 全部博客 (267)
- java.lang (8)
- 问题汇总 (21)
- 异常记录 (20)
- 功能实现 (19)
- 面试总结 (25)
- 技巧总结 (8)
- 常用代码 (4)
- 编程习惯 (3)
- 编码规则 (3)
- java.util (10)
- java.io (1)
- JavaWeb (9)
- MySQL (16)
- SVN (3)
- MyBatis (11)
- Velocity (7)
- 其他知识 (10)
- 人生哲理 (1)
- 人生故事 (1)
- 自我感悟 (1)
- shiro (3)
- 基础知识 (0)
- 问题总结 (1)
- Spring 标签 (1)
- Spring (3)
- 点滴生活 (1)
- DOS (1)
- CAS (4)
- Linux (9)
- Storm (6)
- Shell (1)
- regex (1)
- Collection (4)
- poi (1)
- 经典语句 (1)
- NIO (5)
- concurrent (14)
- RPC (1)
- zookeeper (3)
- 待整理 (2)
- Hadoop (9)
- RabbitMq (2)
- flume (1)
- hive (7)
- hbase (4)
- kafka (1)
- scala (1)
- GC (0)
- java.util.concurrent.atomic (1)
- java.lang.ref (6)
- JVM (2)
- algorithm (1)
- conception (1)
- java key word (1)
- sun.misc (1)
最新评论
RandomAccess
总结:
1.基于 JDK 1.8 源码分析
2.作用
起到判断的作用,即当前集合是否支持随机访问
顺序表(数组形式)还是单链表存储,以便使用更合适的遍历方式
RandomAccess(如ArrayList)还是Sequence List (如LinkedList)
源码:
/* * @(#)RandomAccess.java 1.9 06/04/21 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package java.util; /** * Marker interface used by <tt>List</tt> 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. * * <p>The best algorithms for manipulating random access lists (such as * <tt>ArrayList</tt>) can produce quadratic behavior when applied to * sequential access lists (such as <tt>LinkedList</tt>). Generic list * algorithms are encouraged to check whether the given list is an * <tt>instanceof</tt> 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. * * <p>It is recognized that the distinction between random and sequential * access is often fuzzy. For example, some <tt>List</tt> implementations * provide asymptotically linear access times if they get huge, but constant * access times in practice. Such a <tt>List</tt> implementation * should generally implement this interface. As a rule of thumb, a * <tt>List</tt> implementation should implement this interface if, * for typical instances of the class, this loop: * <pre> * for (int i=0, n=list.size(); i < n; i++) * list.get(i); * </pre> * runs faster than this loop: * <pre> * for (Iterator i=list.iterator(); i.hasNext(); ) * i.next(); * </pre> * * <p>This interface is a member of the * <a href="{@docRoot}/../technotes/guides/collections/index.html"> * Java Collections Framework</a>. * * @since 1.4 */ public interface RandomAccess { }
对于顺序表 for循环通过数组下标访问的效率要高于通过 Iterator 访问的效率;反之,对于单链表要使用 Iterator 方式循环
// ArrayList 的定义 public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, java.io.Serializable // LinkedList 的定义 public class LinkedList<E> extends AbstractSequentialList<E> implements List<E>, Deque<E>, Cloneable, java.io.Serializable
总结:
所以对大量数据进行遍历时要区分当前的List的实现方式
if (list instance of RandomAccess) { for(int m = 0; m < list.size(); m++){} }else{ Iterator iter = list.iterator(); while(iter.hasNext()){} }
博文参考:
RandomAccess接口的使用
发表评论
-
Arrays
2017-10-27 22:54 322Arrays 一、总结 1.基于 jdk 1.8 二、a ... -
Collections
2017-10-27 22:40 350Collections 一、总结 1.基于 JDK 1.8 ... -
LinkedList
2017-10-09 21:18 397LinkedList 一、总结 1.基 ... -
Objects
2017-10-08 12:20 363Objects 一、总结 二、equals Obje ... -
ArrayList
2017-10-08 10:14 412ArrayList 一、总结 1.基于 JDK 1.8 源 ... -
HashSet
2017-09-24 15:04 296HashSet 一、总结(jdk 1.8.0_131) 1 ... -
HashTable
2017-09-23 20:54 345Hashtable 一、对比HashMap 1. 项目Ha ... -
HashMap
2017-03-11 17:48 405HashMap jdk-1.8.0 一、总结 允许key ... -
Vector
2017-03-11 14:57 474Vector 一、总结 1.线程安全 二、类 1.源 ...
相关推荐
最简单的RandomAccess中文读写文件示例
NULL 博文链接:https://lidongfu005.iteye.com/blog/2012223
A Study on Random Access Performance in Next Generation Mobile Network Systems
different random access methods comparison
计算机导论课件:Random Access Memory.pptx
The system block diagram as shown in Figure 1 is designed to capture and store frames captured by the camera on the RC10 board in real-time into block random access memory
RAM存储的耦合故障检测逻辑,基础性论文 March Test Algorithm for 3-Coupling Faults in Random Access Memories
5G蜂窝物联网中大规模机器型通信的速率分裂随机接入机制_Rate-Splitting Random Access Mechanism for Massive Machine Type Communications in 5G Cellular Internet-of-Things.pdf
C++编写的随机访问文件程序,支持对文件的读,写,修改文件,添加文件,删除文件
CAJ文件,几种随机接入协议的仿真性能比较分析
锆掺杂的氧化锌薄膜多比特阻变存储器的双极和单极阻变模式,许定林,唐明华,文中我们报道了锆掺杂的氧化锌器件的单极和双极阻变模式的共存,第一次测试过程之后,具有单极型阻变行为的这种器件在关闭过程中
提示您在一周中的意外时间记录您的想法 您是否曾经想写日记,却没有时间写一篇日记? 好吧,日记为您找到时间了! 随机存取存储器是一个弹出窗口,它会在一周中以随机设置的间隔出现,以供您反射和书写。...
主要介绍了java 中RandomAccess接口源码分析的相关资料,需要的朋友可以参考下
下面小编就为大家带来一篇Java接口RandomAccess全面了解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
FDD-LTE系统中的一种高精度时延估计的随机接入检测算法,彭飞龙,王卫东,在长期演进(LTE)的上行链路传输中,一个用户设备(UE)必须在正常的数据传输之前进行时间同步。所以,物理随机接入信道(PRACH)��
Research and Implementation of Random Access in LTE System
GPP-based Random Access Preamble Detection in TD-LTE
The Research on Random Access Signal Detection Algorithm in LTE Systems
Single - radio multi - subchannel random access for OFDMA wireless networks
Enhanced Random Access and Beam Training for Millimeter Wave Wireless Local Networks With High User Density