哪个更好? array,ArrayList或List(在性能和速度方面) [英] Which is better? array, ArrayList or List (in terms of performance and speed)

查看:278
本文介绍了哪个更好? array,ArrayList或List(在性能和速度方面)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要快速处理我的页面。以上哪一个是首选?支持有正当理由。



编辑:例如:

string str = a,b,c; // str中元素数量的计数不固定
string [] arr = str.Split(' ,') ;

ArrayList al = new ArrayList();
al.Add(str.Split(' ,'));





其中哪一项结果更快?

解决方案

<$ c的容量$ c>数组已修复。

其中, ArrayList 可以动态增加和减小尺寸。



一个数组是类似项目的集合。

其中, ArrayList 可以保存不同类型的项目。



数组是在系统命名空间中。

其中,ArrayList位于System.Collections命名空间中。



一个数组可以有多个维度。

其中, ArrayList 总是只有一个维度。



我们可以设置数组的下限。

其中, ArrayList 的下限始终为零。



Array 更快,因为 ArrayList 使用固定数量的数组。

但是当你向 ArrayList 添加一个元素时它会溢出。它创建一个新的 Array ,并将旧元素中的每个元素复制到新元素。

如果你经常加入,你只会感觉到这一点。



添加是O(n),加到数组是O(1)。



但是因为 ArrayList 使用数组搜索其中的O(1)比正常列表O(n)更快。< br $> b $ b

数组列表

如果你没有超过容量,它将像阵列一样快。

更好的处理和更简单的做事方式。



请参考:

ArrayList和列表集合类型 [ ^ ]


看起来像一个小世界..我想你在以下网站也问了同样的问题......



http://forums.asp.net/p/1808968/5004003.aspx/1?Which+is+better+array+ArrayList+or+List+T+in+术语+ +性能+和+速度+





http://stackoverflow.com/questions/10815565/which-is-better-array-arraylist-or-listt-in-terms-of-performance-and-speed <一个href =http://stackoverflow.com/questions/10815565/which-is-better-array-arraylist-or-listt-in-terms-of-performance-and-speedtarget =_ blanktitle =New窗口>





阵列无疑比其他两个更快。列表与LT; T>比阵列/ arraylist要复杂得多.. Arraylist介于混合阵列的速度和List< t>的便利性之间


希望这可以帮助你

http://stackoverflow.com/questions/10815565/which-is-better-array-arraylist-or-listt-in-terms-of-performance-and-speed [ ^ ]

I require a fast speed in processing my page. Which one of the above is preferred? Support with a valid reason.

Edit: For eg:

string str = "a,b,c"; //Count of the number of elements in str is not fixed
string[] arr = str.Split(',');

ArrayList al = new ArrayList();
al.Add(str.Split(','));



Which of them gives faster results?

解决方案

The capacity of an Array is fixed.
Where as, ArrayList can increase and decrease size dynamically.

An Array is a collection of similar items.
Where as, ArrayList can hold item of different types.

Array is in the System namespace.
Where as, ArrayList is in the System.Collections namespace.

An Array can have multiple dimensions.
Where as, ArrayList always has exactly one dimension.

We can set the lower bound of an Array.
Where as, the lower bound of an ArrayList is always zero.

Array is faster and that is because ArrayList uses a fixed amount of array.
However when you add an element to the ArrayList and it overflows. It creates a new Array and copies every element from the old one to the new one.
You will only feel this if you add to often.

Since the add from ArrayList is O(n) and the add to the Array is O(1).

However because ArrayList uses an Array is faster to search O(1) in it than normal lists O(n).

List over arrays.
If you do not exceed the capacity it is going to be as fast as an array.
Better handling and much easier way of doing things.

Please refer:
ArrayList and List Collection Types[^]


Looks like a small world out there.. I guess you have asked the same question in the following sites also...

http://forums.asp.net/p/1808968/5004003.aspx/1?Which+is+better+array+ArrayList+or+List+T+in+terms+of+performance+and+speed+


http://stackoverflow.com/questions/10815565/which-is-better-array-arraylist-or-listt-in-terms-of-performance-and-speed


Array is undoubtadly faster than the other two. List<t> is much more sophisticated than array / arraylist.. Arraylist is in between blending the speed of array and convenience of List<t>


Hope this may help you
http://stackoverflow.com/questions/10815565/which-is-better-array-arraylist-or-listt-in-terms-of-performance-and-speed[^]


这篇关于哪个更好? array,ArrayList或List(在性能和速度方面)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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