原始数组与 ArrayList [英] Primitive Array vs ArrayList

查看:21
本文介绍了原始数组与 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.

谢谢

推荐答案

原始数组效率更高,因为它们不需要包装对象.Guava 具有由原始数组支持的 List 实现(例如: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.

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

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