数组列表和数组 [英] Arraylist and Arrays

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

问题描述

有什么区别

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 拥有一个支持 Object[].如果您可能会溢出大小并且可以添加,则后备数组将被调整大小"(将创建一个新数组并复制旧数据).

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 implementations also provide additional methods to work on them.

另一件事是您可以将泛型(1.5) 与列表一起使用.

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

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

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