title: What is the best way to remove objects from a List
body: <p>I have the following logic to remove inactive users in the system, since we cannot remove a row while iterating on the list. Is there a better way to handle this?</p>
  
  <pre><code>List&lt;User&gt; users = new ArrayList&lt;User&gt;();
  List&lt;User&gt; removeUsers = new ArrayList&lt;User&gt;();
  
  for (User user : users) {
    if (!user.isActive()) {
        removeUsers.add(user);
    }
  }
  
  users.removeAll(removeUsers);
  </code></pre>