如何ArrayList的工作? [英] How does ArrayList work?

查看:257
本文介绍了如何ArrayList的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么数据结构做一个ArrayList内部使用?

What data structure does an ArrayList use internally?

推荐答案

在内部的的ArrayList 使用了对象[]

当您添加项目到的ArrayList ,即可看到该列表检查是否支持数组有余地。如果有空间,新项目只是在一个空的空间增加。如果没有房间,一个新的,更大,阵列被创建,而旧的阵列被复制到新的一个。

As you add items to an ArrayList, the list checks to see if the backing array has room left. If there is room, the new item is just added at the next empty space. If there is not room, a new, larger, array is created, and the old array is copied into the new one.

现在,有更多的离开房间,而新元素在一个空的空间增加。

Now, there is more room left, and the new element is added in the next empty space.

由于人们非常喜欢的来源$ C ​​$ C:

Since people really like the source code:

/**
 * The array buffer into which the elements of the ArrayList are stored.
 * The capacity of the ArrayList is the length of this array buffer.
 */
private transient Object[] elementData;

直出的JDK。

这篇关于如何ArrayList的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆