gpt4 book ai didi

java - 从列表中删除第一个 'n' 元素而不进行迭代

转载 作者:太空狗 更新时间:2023-10-29 22:37:05 25 4
gpt4 key购买 nike

我需要一种从列表中删除项目的有效方法。如果发生某些情况,我需要从列表中删除前“n”个元素。有人可以建议最好的方法吗?请记住:性能对我来说是一个因素,所以我需要一种比迭代更快的方法。谢谢。

我正在考虑一种方法,通过该方法可以将第“n”项作为列表的开头,以便 0-n 项将被垃圾收集。可能吗?

最佳答案

创建 subList()

Returns a view of the portion of this list between fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.

检查此方法的实现并进行一些测试以确定性能

关于java - 从列表中删除第一个 'n' 元素而不进行迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12456266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com