ArrayList和数组 [英] Arraylist and Arrays

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

问题描述

是什么

ArrayList<Object> al = new ArrayList<Object>(100);

Object[] ar = new Object[100];

有在内部实现,即在存储器的分配有什么区别?
不要在内部内存中保留100插槽?

Is there any difference in the internal implementation i.e. the allocation in the memory? Do both internally reserve 100 slots in the memory?

推荐答案

这是的ArrayList&LT;对象&gt; 持有支持对象[] 。支持数组将被调整(新阵列将被创建和旧的数据将被复制),如果您将可能溢出的规模和增加是可能的。

An ArrayList<Object> holds a backing Object[]. The backing Array will be "resized" (a new array will be created and the old data will be copied over) if you would possibly overflow the size and additions are possible.

List实现还提供了额外的方法对他们的工作。

List implementations also provide additional methods to work on them.

另一件事是,你可能会列出使用泛型(1.5)。

Another thing is that you may use Generics(1.5) with Lists.

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

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