-2
private List<RolePermission> permissionList = new ArrayList<RolePermission>();
ListIterator<RolePermission> iterator = permissionList.listIterator();
permissionList.remove(iterator.next().getRolePermissionName().contains("http"));

我想从包含术语 "http" 的列表中删除那些项目。但这段代码不起作用。

4

2 回答 2

5

您需要使用 iterator.remove();

while (iterator.hasNext())
{
   if (iterator.next().getRolePermissionName().contains("http"))
       iterator.remove();
}
于 2013-09-13T17:09:29.547 回答
1

The method List#remove(java.lang.Object) is in your case not suitable for the type boolean (autoboxed to Boolean), the type which contains() returns. A ClassCastException is thrown.

you could try this to remove using iterator:

private List<RolePermission> permissionList = new ArrayList<RolePermission>();   
ListIterator<RolePermission> iterator = permissionList.listIterator();
RolePermission rp = iterator.next();
if(rp.getRolePermissionName().contains("http")) {
    iterator.remove();
}
于 2013-09-13T17:16:53.947 回答