由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - is access to int[] faster than List?
相关主题
List, LinkedList and Vector几个Java面试题
Java SE6 LinkedList implementation issueJava是如何处理ArrayList和LinkedList的内存的?
leetcode请教: time complexya question regarding spring collection initialization
Generic type cast warning再请教一个 编译错误
immutable listTimer and TimerTask
出个简单题,看你Java APi熟悉到什么程度How to check if an element is in an array?
help: 两个Java的问题问个初级的generic的问题
如何定义这样的数组?问一个 java generic问题
相关话题的讨论汇总
话题: list话题: int话题: access话题: faster话题: linkedlist
进入Java版参与讨论
1 (共1页)
G*********a
发帖数: 1080
1
@@
//bow
g*****g
发帖数: 34805
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.
m******t
发帖数: 2416
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

c*m
发帖数: 836
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.

o***g
发帖数: 2784
5
yes, source of jse 5 is open now

【在 c*m 的大作中提到】
: How did you know? The source is open now?
c*****t
发帖数: 1879
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

G*********a
发帖数: 1080
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 :)

1 (共1页)
进入Java版参与讨论
相关主题
问一个 java generic问题immutable list
今天碰到一个面试题出个简单题,看你Java APi熟悉到什么程度
诡异问题求助help: 两个Java的问题
知道一个key的value, 能不能O(1)从HashMap里拿出对应key和value如何定义这样的数组?
List, LinkedList and Vector几个Java面试题
Java SE6 LinkedList implementation issueJava是如何处理ArrayList和LinkedList的内存的?
leetcode请教: time complexya question regarding spring collection initialization
Generic type cast warning再请教一个 编译错误
相关话题的讨论汇总
话题: list话题: int话题: access话题: faster话题: linkedlist