array数组,arraylist,hashset,vector,linkedlist,速度对比。

来源:互联网 发布:mac 没用 电池不充电 编辑:程序博客网 时间:2024/05/21 10:52

话不多说,数组多是用在知道大小的时候,如果不知道大小,当然从arraylist hashset vector linkedlist中选择一个

 

 

结果让我也有些意外

所有查找都是for each的形式,如果用正常的循环,linkedList的性能就会差非常大,而arraylist就会非常的快ArrayList查找到99998,所消耗的时间:853毫秒

 

数组插入到99998,所消耗的时间:1毫秒
数组查找到99998,所消耗的时间:813毫秒
ArrayList插入到99998,所消耗的时间:11毫秒
ArrayList查找到99998,所消耗的时间:3377毫秒
HashSet插入到99998,所消耗的时间:8毫秒
HashSet查找到99998,所消耗的时间:1745毫秒
Vector插入到99998,所消耗的时间:68毫秒
Vector查找到99998,所消耗的时间:9204毫秒
LinkedList插入到99998,所消耗的时间:14毫秒
LinkedList查找到99998,所消耗的时间:1594毫秒

竟然linkedlist是非常高速的数据结构,如果很计较插入速度arraylist最快,但是所消耗寻找时间也是最常

感谢http://blog.csdn.net/sharpyuce/archive/2007/11/07/1872114.aspx

 

原创粉丝点击