我是 android 新手.. 如何在 android 中过滤 ArrayList
我有以下 JSON 响应
,我想删除那些 null objects
,请引用我的示例:
{
name: "7-11 上海店",
name_en: "7-11 Shanghai",
address: "浦东新区陆家嘴环路1396号",
address_en: "12344",
logo: "http://google.com/images/7eleven.gif",
items: [{
description: "(null)",
quantity: 0,
price: 0
},
{
description: "Item 1",
quantity: 1,
price: 19.9
}
],
amount_due: 19.9
}
在这个例子中我想删除:
{
description: "(null)",
quantity: 0,
price: 0
}
提前致谢!
最佳答案
我终于找到了答案。对于那些与我有同样问题的人。您可以使用此解决方案删除 array
上的特定项目:
yourArray.removeAll(Collections.singleton("item_you_want_to_remove"));
e.g in my case:
myArray.removeAll(Collections.singleton("(null)"));
这很好用!
关于java - Android 中的过滤数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18756684/