[英]How to remove new ArrayList<>?
我尝试过像remove、removeAll、delete这样的方法。 但是所有这些词在 android studio 中都不可用。 我应该用什么词来代替?
public List<ContactObject> receipt = new ArrayList<>();
receipt.add(new ContactObject(object.product_title, object.product_price,
object.img1, object.quantity));
我知道如何添加到列表收据,但如何删除添加的数据?
如果不直接添加新对象,可以像这样删除它:
List<ContactObject> receipts = new ArrayList<>();
ContactObject contactObject = new ContactObject(object.product_title, object.product_price,
object.img1, object.quantity)
receipts.add(contactObject);
// Remove previous added object
receipts.remove(contactObject);
ArrayList
的remove()
取决于 equals() 方法的实现,在您的情况下是ContactObject
。
然后调用 remove() 将解决您的问题。
receipts.remove(contactObject);
removeAll 删除所有给定的对象并返回操作的状态。而 remove 仅删除当前提供的对象。 在您的情况下,您想通过以下方式删除单个对象
yourarraylist.remove(yourobject);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.