时间对Java的ArrayList的复杂性 [英] Time complexity for java ArrayList
本文介绍了时间对Java的ArrayList的复杂性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是的ArrayList
数组或Java中的一个列表?什么是GET操作的时间复杂度,是 O(N)
或 O(1)
?
Is ArrayList
an array or a list in java? what is the time complexity for the get operation, is it O(n)
or O(1)
?
推荐答案
这是的ArrayList
在Java中是一个列表
这是由阵列
的支持。
An ArrayList
in Java is a List
that is backed by an array
.
的 GET(指数)
方法是一个固定的时间, O(1)
操作。
The get(index)
method is a constant time, O(1)
, operation.
在code直接从Java库,为 ArrayList.get(指数)
:
The code straight out of the Java library for ArrayList.get(index)
:
public E get(int index) {
RangeCheck(index);
return (E) elementData[index];
}
基本上,它只是返回一个值直出支持数组的。 ( RangeCheck(指数)
)也是固定时间)
这篇关于时间对Java的ArrayList的复杂性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文