集合源码解析:ArrayList 精讲 初中级人员

图解 | 最全面的 ArrayList 源码解析 (干货满满!!!) 在Java的集合体系中,List接口的实现类ArrayList是非常常用的容器类,比如把查询数据的结果通过ORM框架,将数据存储到ArrayList当中,下面来介绍一下ArrayList是如何实现的,注意下面所有分析均基于JDK8,不同版本可能会有差异。 阅读详情

概述

ArrayList实现了List接口,是顺序容器,即元素存放的数据与放进去的顺序相同,允许放入null元素,底层通过数组实现。除该类未实现同步外,其余跟Vector大致相同。每个ArrayList都有一个容量(capacity),表示底层数组的实际大小,容器内存储元素的个数不能多于当前容量。当向容器中添加元素时,如果容量不足,容器会自动增大底层数组的大小。前面已经提过,Java泛型只是编译器提供的语法糖,所以这里的数组是一个Object数组,以便能够容纳任何类型的对象。

size(), isEmpty(), get(), set()方法均能在常数时间内完成,add()方法的时间开销跟插入位置有关,addAll()方法的时间开销跟添加元素的个数成正比。其余方法大都是线性时间。

为追求效率,ArrayList没有实现同步(synchronized),如果需要多个线程并发访问,用户可以手动同步,也可使用Vector替代。

ArrayList的实现

底层数据结构

    /**
     * The array buffer into which the elements of the ArrayList are stored.
     * The capacity of the ArrayList is the length of this array buffer. Any
     * empty ArrayList with elementData == DEFAULTCAPACITY_EMPTY_ELEMENTDATA
     * will be expanded to DEFAULT_CAPACITY when the first element is added.
     */
    transient Object[] elementData; // non-private to simplify nested class access

    /**
     * The size of the ArrayList (the number of elements it contains).
     *
     * @serial
     */
    private int size;


构造函数

    /**
     * Constructs an empty list with the specified initial capacity.
     *
     * @param  initialCapacity  the initial capacity of the list
     * @throws IllegalArgumentException if the specified initial capacity
     *         is negative
     */
    public ArrayList(int initialCapacity) {
        if (initialCapacity > 0) {
            this.elementData = new Object[initialCapacity];
        } else if (initialCapacity == 0) {
            this.elementData = EMPTY_ELEMENTDATA;
        } else {
            throw new IllegalArgumentException("Illegal Capacity: "+
                                               initialCapacity);
        }
    }

    /**
     * Constructs an empty list with an initial capacity of ten.
     */
    public ArrayList() {
        this.elementData = DEFAULTCAPACITY_EMPTY_ELEMENTDATA;
    }

    /**
     * Constructs a list containing the elements of the specified
     * collection, in the order they are returned by the collection's
     * iterator.
     *
     * @param c the collection whose elements are to be placed into this list
     * @throws NullPointerException if the specified collection is null
     */
    public ArrayList(Collection<? extends E> c) {
        elementData = c.toArray();
        if ((size = elementData.length) != 0) {
            // c.toArray might (incorrectly) not return Object[] (see 6260652)
            if (elementData.getClass() != Object[].class)
                elementData = Arrays.copyOf(elementData, size, Object[].class);
        } else {
            // replace with empty array.
            this.elementData = EMPTY_ELEMENTDATA;
        }
    }


自动扩容

每当向数组中添加元素时,都要去检查添加后元素的个数是否会超出当前数组的长度,如果超出,数组将会进行扩容,以满足添加数据的需求。数组扩容通过一个公开的方法ensureCapacity(int minCapacity)来实现。在实际添加大量元素前,我也可以使用ensureCapacity来手动增加ArrayList实例的容量,以减少递增式再分配的数量。

数组进行扩容时,会将老数组中的元素重新拷贝一份到新的数组中,每次数组容量的增长大约是其原容量的1.5倍。这种操作的代价是很高的,因此在实际使用时,我们应该尽量避免数组容量的扩张。当我们可预知要保存的元素的多少时,要在构造ArrayList实例时,就指定其容量,以避免数组扩容的发生。或者根据实际需求,通过调用ensureCapacity方法来手动增加ArrayList实例的容量。

    /**
     * Increases the capacity of this <tt>ArrayList</tt> instance, if
     * necessary, to ensure that it can hold at least the number of elements
     * specified by the minimum capacity argument.
     *
     * @param   minCapacity   the desired minimum capacity
     */
    public void ensureCapacity(int minCapacity) {
        int minExpand = (elementData != DEFAULTCAPACITY_EMPTY_ELEMENTDATA)
            // any size if not default element table
            ? 0
            // larger than default for default empty table. It's already
            // supposed to be at default size.
            : DEFAULT_CAPACITY;

        if (minCapacity > minExpand) {
            ensureExplicitCapacity(minCapacity);
        }
    }

    private void ensureCapacityInternal(int minCapacity) {
        if (elementData == DEFAULTCAPACITY_EMPTY_ELEMENTDATA) {
            minCapacity = Math.max(DEFAULT_CAPACITY, minCapacity);
        }

        ensureExplicitCapacity(minCapacity);
    }

    private void ensureExplicitCapacity(int minCapacity) {
        modCount++;

        // overflow-conscious code
        if (minCapacity - elementData.length > 0)
            grow(minCapacity);
    }

    /**
     * The maximum size of array to allocate.
     * Some VMs reserve some header words in an array.
     * Attempts to allocate larger arrays may result in
     * OutOfMemoryError: Requested array size exceeds VM limit
     */
    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;

    /**
     * Increases the capacity to ensure that it can hold at least the
     * number of elements specified by the minimum capacity argument.
     *
     * @param minCapacity the desired minimum capacity
     */
    private void grow(int minCapacity) {
        // overflow-conscious code
        int oldCapacity = elementData.length;
        int newCapacity = oldCapacity + (oldCapacity >> 1);
        if (newCapacity - minCapacity < 0)
            newCapacity = minCapacity;
        if (newCapacity - MAX_ARRAY_SIZE > 0)
            newCapacity = hugeCapacity(minCapacity);
        // minCapacity is usually close to size, so this is a win:
        elementData = Arrays.copyOf(elementData, newCapacity);
    }

    private static int hugeCapacity(int minCapacity) {
        if (minCapacity < 0) // overflow
            throw new OutOfMemoryError();
        return (minCapacity > MAX_ARRAY_SIZE) ?
            Integer.MAX_VALUE :
            MAX_ARRAY_SIZE;
    }

add(), addAll()

跟C++ 的vector不同,ArrayList没有push_back()方法,对应的方法是add(E e),ArrayList也没有insert()方法,对应的方法是add(int index, E e)。这两个方法都是向容器中添加新元素,这可能会导致capacity不足,因此在添加元素之前,都需要进行剩余空间检查,如果需要则自动扩容。扩容操作最终是通过grow()方法完成的。


    /**
     * Appends the specified element to the end of this list.
     *
     * @param e element to be appended to this list
     * @return <tt>true</tt> (as specified by {@link Collection#add})
     */
    public boolean add(E e) {
        ensureCapacityInternal(size + 1);  // Increments modCount!!
        elementData[size++] = e;
        return true;
    }

    /**
     * Inserts the specified element at the specified position in this
     * list. Shifts the element currently at that position (if any) and
     * any subsequent elements to the right (adds one to their indices).
     *
     * @param index index at which the specified element is to be inserted
     * @param element element to be inserted
     * @throws IndexOutOfBoundsException {@inheritDoc}
     */
    public void add(int index, E element) {
        rangeCheckForAdd(index);

        ensureCapacityInternal(size + 1);  // Increments modCount!!
        System.arraycopy(elementData, index, elementData, index + 1,
                         size - index);
        elementData[index] = element;
        size++;
    }


add(int index, E e)需要先对元素进行移动,然后完成插入操作,也就意味着该方法有着线性的时间复杂度。

addAll()方法能够一次添加多个元素,根据位置不同也有两个版本,一个是在末尾添加的addAll(Collection<? extends E> c)方法,一个是从指定位置开始插入的addAll(int index, Collection<? extends E> c)方法。跟add()方法类似,在插入之前也需要进行空间检查,如果需要则自动扩容;如果从指定位置插入,也会存在移动元素的情况。 addAll()的时间复杂度不仅跟插入元素的多少有关,也跟插入的位置相关。

    /**
     * Appends all of the elements in the specified collection to the end of
     * this list, in the order that they are returned by the
     * specified collection's Iterator.  The behavior of this operation is
     * undefined if the specified collection is modified while the operation
     * is in progress.  (This implies that the behavior of this call is
     * undefined if the specified collection is this list, and this
     * list is nonempty.)
     *
     * @param c collection containing elements to be added to this list
     * @return <tt>true</tt> if this list changed as a result of the call
     * @throws NullPointerException if the specified collection is null
     */
    public boolean addAll(Collection<? extends E> c) {
        Object[] a = c.toArray();
        int numNew = a.length;
        ensureCapacityInternal(size + numNew);  // Increments modCount
        System.arraycopy(a, 0, elementData, size, numNew);
        size += numNew;
        return numNew != 0;
    }

    /**
     * Inserts all of the elements in the specified collection into this
     * list, starting at the specified position.  Shifts the element
     * currently at that position (if any) and any subsequent elements to
     * the right (increases their indices).  The new elements will appear
     * in the list in the order that they are returned by the
     * specified collection's iterator.
     *
     * @param index index at which to insert the first element from the
     *              specified collection
     * @param c collection containing elements to be added to this list
     * @return <tt>true</tt> if this list changed as a result of the call
     * @throws IndexOutOfBoundsException {@inheritDoc}
     * @throws NullPointerException if the specified collection is null
     */
    public boolean addAll(int index, Collection<? extends E> c) {
        rangeCheckForAdd(index);

        Object[] a = c.toArray();
        int numNew = a.length;
        ensureCapacityInternal(size + numNew);  // Increments modCount

        int numMoved = size - index;
        if (numMoved > 0)
            System.arraycopy(elementData, index, elementData, index + numNew,
                             numMoved);

        System.arraycopy(a, 0, elementData, index, numNew);
        size += numNew;
        return numNew != 0;
    }


set()

既然底层是一个数组ArrayList的set()方法也就变得非常简单,直接对数组的指定位置赋值即可。

public E set(int index, E element) {
    rangeCheck(index);//下标越界检查
    E oldValue = elementData(index);
    elementData[index] = element;//赋值到指定位置,复制的仅仅是引用
    return oldValue;
}


get()

get()方法同样很简单,唯一要注意的是由于底层数组是Object[],得到元素后需要进行类型转换。

public E get(int index) {
    rangeCheck(index);
    return (E) elementData[index];//注意类型转换
}

remove()

remove()方法也有两个版本,一个是remove(int index)删除指定位置的元素,另一个是remove(Object o)删除第一个满足o.equals(elementData[index])的元素。删除操作是add()操作的逆过程,需要将删除点之后的元素向前移动一个位置。需要注意的是为了让GC起作用,必须显式的为最后一个位置赋null值。

public E remove(int index) {
    rangeCheck(index);
    modCount++;
    E oldValue = elementData(index);
    int numMoved = size - index - 1;
    if (numMoved > 0)
        System.arraycopy(elementData, index+1, elementData, index, numMoved);
    elementData[--size] = null; //清除该位置的引用,让GC起作用
    return oldValue;
}

关于Java GC这里需要特别说明一下,有了垃圾收集器并不意味着一定不会有内存泄漏。对象能否被GC的依据是是否还有引用指向它,上面代码中如果不手动赋null值,除非对应的位置被其他元素覆盖,否则原来的对象就一直不会被回收。

trimToSize()

ArrayList还给我们提供了将底层数组的容量调整为当前列表保存的实际元素的大小的功能。它可以通过trimToSize方法来实现。代码如下:

    /**
     * Trims the capacity of this <tt>ArrayList</tt> instance to be the
     * list's current size.  An application can use this operation to minimize
     * the storage of an <tt>ArrayList</tt> instance.
     */
    public void trimToSize() {
        modCount++;
        if (size < elementData.length) {
            elementData = (size == 0)
              ? EMPTY_ELEMENTDATA
              : Arrays.copyOf(elementData, size);
        }
    }

indexOf(), lastIndexOf()

获取元素的第一次出现的index:

/**
     * Returns the index of the first occurrence of the specified element
     * in this list, or -1 if this list does not contain the element.
     * More formally, returns the lowest index <tt>i</tt> such that
     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
     * or -1 if there is no such index.
     */
    public int indexOf(Object o) {
        if (o == null) {
            for (int i = 0; i < size; i++)
                if (elementData[i]==null)
                    return i;
        } else {
            for (int i = 0; i < size; i++)
                if (o.equals(elementData[i]))
                    return i;
        }
        return -1;
    }

获取元素的最后一次出现的index:

    /**
     * Returns the index of the last occurrence of the specified element
     * in this list, or -1 if this list does not contain the element.
     * More formally, returns the highest index <tt>i</tt> such that
     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
     * or -1 if there is no such index.
     */
    public int lastIndexOf(Object o) {
        if (o == null) {
            for (int i = size-1; i >= 0; i--)
                if (elementData[i]==null)
                    return i;
        } else {
            for (int i = size-1; i >= 0; i--)
                if (o.equals(elementData[i]))
                    return i;
        }
        return -1;
    }

Fail-Fast机制:

ArrayList也采用了快速失败的机制,通过记录modCount参数来实现。在面对并发的修改时,迭代器很快就会完全失败,而不是冒着在将来某个不确定时间发生任意不确定行为的风险。

pop_back()的用法及运行机制 vector在c++中非常好用,简单的说,vector是一个能够存放任意类型的动态数组,能够增加和压缩数据。 一般使用push_back()和pop_back()函数将数据存放进容器末尾。 如下例程: #include <iostream> #include <vector> using namespace std; int main() { vector<int> nums; for(int i=0;i<4;i++){ nums.push.. 阅读详情

相关推荐

保姆级教程:在RK3568上调试RGMII网口,从设备树到PHY驱动的完整避坑指南

本文提供RK3568开发板上RGMII网口调试的完整指南,涵盖硬件检查、设备树配置、驱动加载及性能优化。通过详细步骤和实战案例,帮助开发者避开常见陷阱,确保以太网功能稳定运行,特别关注PHY驱动和MDIO总线的调试技巧。

weixin_26821003的博客 323

ArrayList 源码

集合类中,最基础也是最常用的,大概就是ArrayList了吧。ArrayList的本质,是一个可变长的数组。那有人可能就会问,哎呀这个数组老简单了,有什么好看的啊……但事实上,在面试时,有些人还是对源码的细节说不清楚,从而留下较差的印象。这里,我就带着大家,一点一点地梳理一下,ArrayList的底层源码吧。概览..ArrayList类继承自AbstractList类,且实现了List、RandomAccess、Cloneable和Serializable接口。...

ironmanoOOoo的博客 1891

MagicDraw-需求图

MagicDraw学习笔记

木头征的博客 4138

java---ArrayList源码解析

ArrayList 底层就是一个数组,依赖其扩容机制(后面会提到)它能够实现容量的动态增长,所以 ArrayList 就是数据结构中顺序表的一种具体实现。

m0_58196614的博客 1788

Grok 3国内怎么用?超详细使用指南+实用指令模板

主要是用于快速分析学术论文,提取关键信息,总结研究成果。Analyze the following research paper: [粘贴或上传论文内容]1. Extract key findings, methodologies, and conclusions. (提取主要发现、方法和结论。2. Identify statistical significance and data points. (识别统计显著性和数据点。

Survivor_sl的博客 1万+

UReport2 报表设计器 在线表格

UReport2官网 一、UReport2报表设计器 UReport2是一个开源的可视化报表设计器,功能强大,操作简单,可以实现复杂的报表统计,有各种各样的导出和打印功能,支持导入Excel表格! 1、报表设计器 2、设计一个简单的用户列表展示 二、可编辑表格 扩展了layui的表格,支持多元化数据编辑(单选,多些、日期、下拉联动),开发简单、高效、便捷。有了它就可以轻松开发类似进销存系统的表格录入功能了,用户拿来即用! 三、主从表录......

ejinxian的专栏 2万+

【JAVA集合篇】ArrayList源码详解

ArrayList是一种以数组实现的List,与数组相比,它具有动态扩展的能力,因此也可称之为动态数组。在ArrayList集合里面可以存储任何类型的数据, 而且它是一个顺序容器,存放的数据顺序就是和我们放入的顺序是一致的,而且它还允许我们放入null元素。

初念初恋的博客 1731

YOLOv12涨点改进 | 独家创新-注意力改进篇 | ECCV 2024 | YOLOv12引入AgentAttention代理注意力模块,兼顾 Softmax 和线性注意力优点,提高检测精度

🔥本文给大家介绍使用Agent Attention模块改进YOLOv12网络模型。其主要作用是通过引入高效的代理token来减少计算复杂度,同时保留全局上下文建模能力。相比传统的Softmax注意力,Agent Attention通过代理token聚合并广播信息,从而降低了模型在处理高分辨率图像时的计算负担,并显著提高了推理速度。其优势在于保持了目标检测中的全局信息处理能力,同时加速了生成过程,特别是在高分辨率场景下,可以提高检测精度、减少内存消耗,并提升处理速度。

Ai缝合怪、助力小伙伴高效发论文 157

arraylist 并发_【成都校区*精品*Java中ArrayList源码解析】

Java中ArrayList源码解析前言 集合是Java开发人员必不可少的一个工具,而ArrayList是Java集合中的最为常用的一种,了解其底层原理能让我们更好的去使用它。本文将通过对于ArrayList类中源代码的分析来逐步揭开其底层原理的神秘面纱 。1. ArrayList的本质 我们从ArrayList类源码中找到一个非常重要的成员变量:transient Object[] elemen...

weixin_33201508的博客 92

XGBoost原生接口和Sklearn接口参数详解

XGBoost原生接口和Sklearn接口参数详解

算法工程师 2656

骚戴笔记公告

骚戴笔记公告

我从不打没有准备的仗! 2万+

Java中ArrayList源码解析

Java中ArrayList源码解析 前言集合是Java开发人员必不可少的一个工具,而ArrayList是Java集合中的最为常用的一种,了解其底层原理能让我们更好的去使用它。本文将通过对于ArrayList类中源代码的分析来逐步揭开其底层原理的神秘面纱 。 1. ArrayList的本质我们从ArrayList类源码中找到一个非常重要的成员变量: [Java]纯文本查看复制代码 ?...

xiaoyaGrace的博客 220

2020年信奥赛C++提高组csp-s初赛真题及答案解析(阅读程序第3题)

2020年信奥赛C++提高组csp-s初赛真题及答案解析(阅读程序第3题)

王老师青少年编程 992

Java集合框架核心解析与高频面试题精讲

Java集合框架是数据处理的基础架构,其核心原理基于数据结构与算法的高效实现。Collection和Map两大体系分别处理线性集合与键值映射,其中ArrayList和HashMap凭借数组存储和哈希算法实现O(1)访问性能。在多线程场景下,ConcurrentHashMap通过CAS与分段锁机制保证线程安全,而fail-fast机制则维护集合遍历时的数据一致性。实际开发中,合理的初始容量设置(如HashMap初始容量=预期元素数/0.75)能显著提升性能,在大数据场景下,原始类型集合如TIntArrayLi

weixin_30633405的博客 375

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

java源码分析之集合框架 ArrayList和LinkedList的区别05

List概括 先来回顾一下List在Collection中的的框架图: 从图中我们可以看出: 1. List是一个接口,它继承与Collection接口,代表有序的队列。 2. AbstractList是一个抽象类,它继承于AbstractCollection。AbstractList实现了List接口中全部方法。AbstractList相比A

坚定目标,超越自我 1448

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

JDK源码解析集合篇--ArrayList全解析

对于一个集合的使用,我们首先关注的是: 1、 增删改查的特点(时间复杂度是怎样的) 适用于随机访问 2、是否允许空 允许为空 3、是否允许重复数据 允许 4、是否有序,有序的意思是读取数据的顺序和存放数据的顺序是否一致 有序 5、是否线程安全 非线程安全ArrayList实现原理ArrayList就是一个以数组形式实现的集合,但是它实现了长度可变。我们可以看其源码属性:

怕什么真理无穷, 进一寸有一寸的欢喜 377

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

源码终结者之ArrayList源码解读

前言 同学们好,欢迎来到源码不可怕系列,很多同学在编程的道路上会感觉读源码有很大的难度, 认为我们都是普普通通的开发人员, 没必要去研究那么"高大上"的底层源码, 实际则不然, 读源码有很多的好处, 并且可以解决我们在工作or学习中遇见的疑难杂症, 一个高级程序员是需要去深入研究一些技术的,那么读源码的能力则极其重要。那么就从今天起, 跟随我一起来撕开各种技术源码的面纱吧! ArrayList介绍 ArrayList 是一个JDK集合中的一个功能简单且实现难度较低的工具类,数据结构也比较单一,是由数组构成的

冷风DMW的博客 1509

从源码角度来看看ArrayList的实现

前言 这个分类中,将会写写Java中的集合。集合是Java中非常重要而且基础的内容,因为任何数据必不可少的就是该数据是如何存储的,集合的作用就是以一定的方式组织、存储数据。这里写的集合,一部分是比较常见的、一部分是不常用但是我个人平时见到过的,一些比较相似的集合(比如HashMap和Hashtable)就只讲一个,突出它们之间的区别即可。 最后,要指出一点,对于集合,我认为关注的点主要有四点: ...

lizhenglyg的博客 244

图解集合1:ArrayList

转自:https://www.cnblogs.com/xrq730/p/4989451.html 前言 这个分类中,将会写写Java中的集合。集合是Java中非常重要而且基础的内容,因为任何数据必不可少的就是该数据是如何存储的,集合的作用就是以一定的方式组织、存储数据。这里写的集合,一部分是比较常见的、一部分是不常用但是我个人平时见到过的,一些比较相似的集合(比如HashMap和Hashtab...

桥的博客 238

ArrayList源码详解

ArrayList源码详解 ArrayList作为开发最最常用的容器,了解并掌握其底层原理是每个开发人员必备的技能。 一、关键属性 /** * Default initial capacity. * 默认初始化容量 */ private static final int DEFAULT_CAPACITY = 10; /** * Shared empty array instance used for empty instances. * 空数组,用于空的实例化 */ private sta

ITxiaofeixiang的博客 494

Java 集合源码梳理:ArrayList 与 LinkedList 底层差异及选用场景

日常业务开发中,List 集合是使用频率很高的数据容器,很多开发者在编码时随意选用 ArrayList 或 LinkedList,忽略两者底层结构带来的性能差距,高并发、大数据量场景下容易出现接口响应缓慢、内存占用过高等问题。集合选型没有绝对最优,只有贴合业务场景的合适方案。扩容逻辑:默认初始容量 10,每次扩容为原数组长度 1.5 倍,扩容时会新建数组并拷贝全部元素,大批量新增数据会产生额外开销;查询特性:无随机下标访问,根据索引取值需要从头 / 尾遍历链表,时间复杂度 O (n),数据量大时查询很慢;

a192837456的博客 202

Java集合ArrayList源码解析

对于集合,我认为关注的点主要有四点: 1、是否允许空 2、是否允许重复数据 3、是否有序,有序的意思是读取数据的顺序和存放数据的顺序是否一致 4、是否线程安全  ArrayList ArrayList是最常见以及每个Java开发者最熟悉的集合类了,顾名思义,ArrayList就是一个以数组形式实现的集合,以一张表格来看一下ArrayList里面有哪些基本的元素:

Darling_0604的博客 308

Java集合类ArrayList、LinkedList、vector、SynchronizedList详解

Java集合类ArrayList、LinkedList、vector、SynchronizedList底层详解

LovelyCoder 720

图解集合 1 :ArrayList

前言这个分类中,将会写写Java中的集合。集合是Java中非常重要而且基础的内容,因为任何数据必不可少的就是该数据是如何存储的,集合的作用就是以一定的方式组织、存储数据。这里写的集合,一部分是比较常见的、一部分是不常用但是我个人平时见到过的,一些比较相似的集合(比如HashMap和Hashtable)就只讲一个,突出它们之间的区别即可。最后,要指出一点,对于集合,我认为关注的点主要有四点: 是否允许

Nobigo 852

集合类源码整理

集合是Java的核心知识,我们在日常的工作和学习中经常会使用到。集合作为一种容器,通常用到的就是它的增删改查功能。对我自己来说,虽然我会用,但是在相当长的一段时间里是知其然不知其所以然。学习集合的源码知识,了解他的底层数据结构是作为一名技术人员的必修课。在后续的一段时间,我会持续的更新相关的源码知识,如果大家感兴趣,请关注我,一起学习。每篇文章都会从集合的成员变量、涉及的数据结构、构造方法、常用方...

MAX_VALUE的博客 318
上一篇: 公司刚来的阿里p8,看完我构建的分布式框架,甩给我一份文档
下一篇: 集合源码解析: Stack and Queue精讲 初中级人员
Java技术那些事儿
博客等级 码龄5年 2306粉丝 2584原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值