数组或列表在Java中。这是更快? [英] Array or List in Java. Which is faster?

查看:142
本文介绍了数组或列表在Java中。这是更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要保持几千串在内存中使用Java串行访问。我应该将它们存储在一个数组或我应该使用某种形式的列表?

I have to keep thousands of strings in memory to be accessed serially in Java. Should I store them in an array or should I use some kind of List ?

因为数组保存在一个连续的内存块中的所有数据(不像列表),将使用一个阵列来存储数千串会出现问题?

Since arrays keep all the data in a contiguous chunk of memory (unlike Lists), would the use of an array to store thousands of strings cause problems ?

答:的共识是,性能差异较小。 List接口提供了更多的灵活性。

Answer: The common consensus is that the performance difference is minor. List interface provides more flexibility.

推荐答案

我建议你使用一个分析器来测试这是更快。

I suggest that you use a profiler to test which is faster.

我个人的看法是,你应该使用列表。

My personal opinion is that you should use Lists.

我在一个大codeBase类和开发商previous工作组使用数组处处。它使code非常不灵活。改变它的大块到列表后,我们发现速度没有区别。

I work on a large codebase and a previous group of developers used arrays everywhere. It made the code very inflexible. After changing large chunks of it to Lists we noticed no difference in speed.

这篇关于数组或列表在Java中。这是更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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