如何一个ArrayList比较动态数组 [英] how does an ArrayList compare to a dynamic array

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

问题描述

的ArrayList 仅仅是一个动态数组的接口?或者,他们同样的事情?

Is an ArrayList is just the interface for a dynamic array? Or are they the same thing?

这样的:的ArrayList 对应动态数组,的HashMap 对应地图

like: ArrayList corresponds to dynamic array, HashMap corresponds to Map ?

除了我没有看到任何的Java API的是这样一个的动态数组的,除非它是的ArrayList

except I don't see any Java API for something like a dynamic array, unless it is ArrayList?

在这种情况下,他们将同样的事情!

in that case they would be the same thing !

presumably他们是同样的事情?

presumably they are the same thing?

推荐答案

是的。总之。

一个较长的解释是,一个的ArrayList 是使用阵列进行存储,而不是一个链表,双向链表或集合类似。这意味着,它提供了使用阵列的所有好处,而Java的外观尺寸为您(动态)。

Yes. In short.

A longer explanation is that an ArrayList is a collection that uses arrays for storage, rather than a linked list, doubly linked list or similar. This means that it gives all the benefits of using an Array, whilst Java looks after the mechanics of sizing the Array for you (dynamically).

我似乎记得初始阵列与一个默认的最大尺寸(这可以由用户指定)创建。如果收集运行的空间,那么较大的阵列中创建和原数组的内容复制到新的。在尺寸的增量设定为prevent这种情况发生过于频繁,作为操作是相当昂贵的。

I seem to remember that the initial array is created with a default maximum size (which can be specified by the user). Should the collection run out of space, then a larger array is created and the contents of the original array copied into the new one. The increment in size is set to prevent this happening too often, as the operation is fairly costly.

Java也提供了矢量收藏这是类似的,但也是线程安全的,请参见:<一href=\"http://stackoverflow.com/questions/2986296/what-are-the-differences-between-arraylist-and-vector\">What是ArrayList和Vector的区别?。

Java also offers the Vector collection which is similar, but is also thread safe, see: What are the differences between ArrayList and Vector?.

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

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