zoukankan      html  css  js  c++  java
  • ArrayList和LinkedList的区别

    以下为jdk1.6中ArrayList中的构造函数源码。

    1.     public ArrayList(int initialCapacity) {
    2.         super();
    3.         if (initialCapacity < 0)
    4.             throw new IllegalArgumentException("Illegal Capacity: "+
    5.                                                initialCapacity);
    6.         this.elementData = new Object[initialCapacity];
    7.     }
    8.     /**
    9.      * Constructs an empty list with an initial capacity of ten.
    10.      */
    11.     public ArrayList() {
    12.         this(10);
    13.     }

    可以看出在建立ArrayList对象的时候。
    默认建立了一个长度为10的Object数组。但是这只是ArrayList 的实现方式。
    在LinkedList中是这样的。

    1. public LinkedList() {
    2. header.next = header.previous = header;
    3. }

    如果有C 基础的话。应该知道这是链表实现的。
    这就是为什么LinkedList的增删效率高!查询效率低!而ArrayList 的查询效率高!增删效率低!
    这就是说其实数组只是集合实现的一种方式。

  • 相关阅读:
    每日汇报
    每周总结
    构建之法阅读笔记2
    每周总结
    每周总结
    体温上报软件开发
    体温上报软件开发
    构建之法阅读笔记1
    体温上报软件开发
    大二下学期团队项目(爬取豆瓣电影)
  • 原文地址:https://www.cnblogs.com/gameoverit/p/6165408.html
Copyright © 2011-2022 走看看