调整集合以容纳大量对象 [英] Tuning collection to hold large number of objects

查看:115
本文介绍了调整集合以容纳大量对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果一个集合,如数组列表,将存储自定义对象(例如具有几个属性的人)在成千上万,在我的代码或集合的构造函数中做任何事情来准备这样一个大集合。

If a collection, like an arraylist, will be storing custom objects (eg Person with several properties) in the thousands, is there anything to do in my code or in the constructor of the collection to prepare it for such a large collection.

我不是真的考虑专用线程等,但更多的负载因素的线路(我需要触摸这个上述情况吗?

I'm not really thinking of dedicated threads etc, but more along the lines of the load factor (do I need to touch this for the above scenario?).

感谢

推荐答案

尺寸将接近最终尺寸,以便最小化调整次数:

I'd just initialize the collection to a size that would be close to the final size, in order to minimize the number of resizings:

List<Person> persons = new ArrayList<Person>(1024);

这篇关于调整集合以容纳大量对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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