基本数组VS的ArrayList [英] Primitive Array vs ArrayList

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

问题描述

我收到XML和需要转换到一个基本数组或ArrayList中。
有在存储器和垃圾收集方面在性能方面多大差别?
我的应用程序将创建这些对象的每一秒一千,我需要,我需要的实时性能,以减少GC。

I am receiving XML and need to convert to either a primitive Array or ArrayList. Is there much difference in terms of performance in terms of memory and garbage collection? My application will be creating thousand of these objects every second and I need to minimize GC as I need real-time performance.

Thxs

推荐答案

原始阵列更有效,因为它们不需要包装对象。 番石榴有由原始阵列(例如支持List实现:<一href=\"http://guava-libraries.google$c$c.com/svn/trunk/javadoc/com/google/common/primitives/Ints.html#asList%28int...%29\"相对=nofollow> Ints.asList(INT []) ),也许这可能是你一个合理的解决方案:得到一个集合的权力,但只有当你真正需要它们的使用对象。

Primitive arrays are much more efficient, as they don't require wrapper objects. Guava has List implementations that are backed by primitive arrays (example: Ints.asList(int[])), perhaps that could be a reasonable solution for you: get the power of a collection but only use Objects when you actually need them.

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

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