栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

从列表中删除对象

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从列表中删除对象

两者都具有相同的时间复杂度-O(n),但是恕我直言,该

linkedList
版本会更快,尤其是在大型列表中,因为当您从数组(
ArrayList
)中删除一个元素时,右侧的所有元素都必须向左移动-
顺序来填充空数组元素,而
linkedList
只需重新连接4个引用

这是其他列表方法的时间复杂度:

For linkedList<E>    get(int index) - O(n)    add(E element) - O(1)    add(int index, E element) - O(n)    remove(int index) - O(n)    Iterator.remove() is O(1)     ListIterator.add(E element) - O(1)For ArrayList<E>    get(int index) is O(1)     add(E element) is O(1) amortized, but O(n) worst-case since the array must be resized and copied    add(int index, E element) is O(n - index) amortized,  O(n) worst-case     remove(int index) - O(n - index) (removing last is O(1))    Iterator.remove() - O(n - index)    ListIterator.add(E element) - O(n - index)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/419698.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号