zoukankan      html  css  js  c++  java
  • 再看看ArrayList

    public class ArrayListDemo {
        public static void main(String[] args) {
            int size = 2000000;
            List<String> list = new ArrayList<>();
            for(int i = 0;i<size;i++) {
                list.add("Just some test data");
            }
    
            long startTime = System.currentTimeMillis();
            for(int i = 0;i<size;i++) {
                list.get(i);
                if(i%10000 ==0) {
                    System.out.println("query 10000 elements spend: "+ (System.currentTimeMillis()-startTime));
                    startTime = System.currentTimeMillis();
                }
            }
        }
    }

    程序运行结果:

    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 10
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0
    query 10000 elements spend: 0

    ......
    和LinkedListWorngDemo对比可以充分说明一个问题
  • 相关阅读:
    【转】一个lucene的官网例子
    mongodb(回滚)
    mongodb( 实现join)
    JSON.stringify && JSON.parse
    js下的面向对象
    node(规则引擎)
    objective-c(内存管理)
    STM32F0xx_USART收发配置详细过程
    STM32F0xx_GPIO配置详细过程
    STM32F0_新建软件工程详细过程
  • 原文地址:https://www.cnblogs.com/danawill/p/6938675.html
Copyright © 2011-2022 走看看