Redian新闻
>
is access to int[] faster than List<int>?
avatar
g*g
2
I mean for ArrayList, for LinkedList, of course it's different.
I didn't see the source, but if you decompile it, I believe
you'll see something like that.
avatar
m*t
3

There isn't a simple answer to this question. While it is safe to say int[]
is faster than most if not all the List implementations, the actual
difference depends the implementations, e.g., random access with ArrayList
is O(c), and O(n) for LinkedList.

【在 G*********a 的大作中提到】
: @@
: //bow

avatar
c*m
4
How did you know? The source is open now?

【在 g*****g 的大作中提到】
: I mean for ArrayList, for LinkedList, of course it's different.
: I didn't see the source, but if you decompile it, I believe
: you'll see something like that.

avatar
o*g
5
yes, source of jse 5 is open now

【在 c*m 的大作中提到】
: How did you know? The source is open now?
avatar
c*t
6
Yes.
1. int[] is only a single function call to set/retrieve a primary value.
2. List involves 2 (one to retrieve and one to get value from Integer
object. This is not counting the fact that List internally
may access an array itself using another function call. The list
algorithm may also be slower. There are maybe several logic checks as
well. In short, List has a lot more overhead costs.
When in doubt, read the source code :)

【在 G*********a 的大作中提到】
: @@
: //bow

avatar
G*a
7
thanks! :)
//bow

【在 c*****t 的大作中提到】
: Yes.
: 1. int[] is only a single function call to set/retrieve a primary value.
: 2. List involves 2 (one to retrieve and one to get value from Integer
: object. This is not counting the fact that List internally
: may access an array itself using another function call. The list
: algorithm may also be slower. There are maybe several logic checks as
: well. In short, List has a lot more overhead costs.
: When in doubt, read the source code :)

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。