列表vs数组 - 什么时候使用什么? [英] Lists vs Arrays - when to use what?

查看:150
本文介绍了列表vs数组 - 什么时候使用什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Java比较陌生,多年来,我不得不解决各种各样的编程问题,需要收集的数据的数量是程序员是未知的。

I am relatively new to Java and over the years I had to solve all sorts of programming problems where the number of data that needs to be collected is really unknown to the programmer.

当程序员无法知道需要收集的变量的数量时,使用列表收集字符串或整数值是一个很好的习惯吗?

Is it a good convention to use Lists to collect strings or integer values when the programmer has no way of knowing the amount of variables that needs to be collected? Or is there a better way to handle this using dynamic arrays in Java?

推荐答案

如果有疑问,使用List是可能的即使你知道长度也是一个更好的选择。

If in doubt, using a List is likely to be a better choice even if you know the length.

使用数组可以更好的性能,但你需要一个专家知道这是一个好主意,当它只是使你的解决方案更复杂。

Using an array can be better for performance, but you need to be an expert to know when this is a good idea, and when it just makes your solution more complicated.

BTW:没有这样的事情动态数组 Java。

BTW: There is no such thing as dynamic arrays in Java.

这篇关于列表vs数组 - 什么时候使用什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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