java - 对象 ArrayList 中 contains(Object o) 的时间复杂度

标签 java arraylist time-complexity

正如标题所说,我想知道 contains() 的时间复杂度是多少ArrayList 的方法是。

最佳答案

O(n)

The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). The constant factor is low compared to that for the LinkedList implementation.

http://download.oracle.com/javase/6/docs/api/java/util/ArrayList.html

关于java - 对象 ArrayList 中 contains(Object o) 的时间复杂度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5771740/

相关文章:

java - 尝试将 css 样式表与 JavaFX 一起使用时出现 "loadStylesheetUnPrivileged"错误

java - 我在哪里可以获得 JOGL 的更新版本?可能与 NetBeans 一起工作?

android - 如何从android中的firebase中检索List对象

algorithm - 这种检查数字 k 是否可以表示为 n^p 的方法的时间复杂度是多少

java - 在 while 循环中检查输入是否为数字

java - 由于无法在循环中再次获取用户输入而导致程序重复 switch-case

android - 从 xml 文件中获取保存的 X 和 Y 数组点?

java - 返回一个回文数组 - 将 arraylist 转换为数组

数组函数的 JavaScript 运行时复杂度

algorithm - 以特殊方式设置不相交?