关于java列表删除的问题 [英] question on java list remove

查看:32
本文介绍了关于java列表删除的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方法public boolean remove(Object o) of List 从列表中删除一个对象,但不移动后面的元素.只是将对象值清零.
恕我直言,这是一个不直观的设计选择,因为删除前后列表的大小保持不变.
有没有一种优雅的方法来获取元素移动的列表?

The method public boolean remove(Object o) of List removes an object from list but does not shift the elements following.Just nulls the object value.
IMHO this is an uninintuitive design choice since the size of the list before and after removal remains the same.
Is there an elegant way to get a list with the elements shifted?

谢谢

推荐答案

不,它不是这样做的.该元素被删除,其后的所有索引都减一.是什么让您认为它的行为有所不同?

No, that's not what it does. The element is removed and all indices following it are reduced by one. What makes you think it acts differently?

这篇关于关于java列表删除的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆