Removal of the specified object in the collection list

1. Use of list.remove (obj), no effect;

2. Use the removeAll also does not work:

  List<User> userRemove = new ArrayList<User>();
        //找出要删除的用户
        for (User result : list)
        {
            if (result.getId() == 1 || result.getId() == 3)
            {
                userRemove.add(result);
            }
        }
        list.removeAll(userRemove);

3. Finally use Iteator achieve the specified object is removed out of the collection:

   Iterator<User> it =list.iterator();
        while (it.hasNext())
        {
        	User userObj = it.next();
            if (StringUtils.isBlank(userObj.getProjects()))
            {
                it.remove();  
            }
        }

Guess you like

Origin blog.csdn.net/shenxiaomo1688/article/details/88060583