简体   繁体   English

从集合中删除N元素

[英]Remove the N element from a collection

I need to remove the element in the position "n" from a collection and get that element. 我需要从集合中删除位置“ n”中的元素并获取该元素。 Is there any method that already exists? 有没有已经存在的方法?

With a List, you can do List.remove(int index) , which returns the element removed. 使用列表,您可以执行List.remove(int index) ,该操作返回删除的元素。

With a generic Collection, you can't remove an item by index, because not all Collections are ordered by index. 对于通用Collection,您无法按索引删除项目,因为并非所有Collection都按索引排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM