java中最快的数据类型,用于以与存储的顺序相同的顺序检索整数(Fastest datatype in java for retrieving integers in the same order a

编程入门 行业动态 更新时间:2024-10-26 05:23:32
java中最快的数据类型,用于以与存储的顺序相同的顺序检索整数(Fastest datatype in java for retrieving integers in the same order as stored)

我需要编写一个程序,它将获得大量的输入整数,大约10 ^ 6个数字,并以相同的顺序处理它们。 迭代中哪个数据结构最快..? 该程序必须在3秒内运行。

I need to write a program which will get very large number of input integers, about 10^6 numbers and process them in the same order. Which data structure will be the fastest in iteration..? The program must run within 3 seconds.

最满意答案

对于相同顺序的迭代,如果性能是一个关键问题,你可以使用一个简单的数组 (但它不允许动态增长数组而不需要额外的努力,所以你通常应该知道数组的最终大小才能使用它)。

您还可以使用List接口。 LinkedList和ArrayList支持有效的迭代和追加。 这样可以更好地维护代码,但性能稍差。

For iteration in the same order you can use a simple array if performance is a critical issue (but it does not allow growing the array dynamically without some extra effort, so you should usually be aware of the final size of the array in order to use it).

You can also use a List interface. Both LinkedList and ArrayList support efficient iterating and appending. This allows better maintainability for your code, but suffers from slightly worse performances.

更多推荐

本文发布于:2023-07-31 23:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1348995.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:顺序   整数   数据类型   最快   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!