title: Why do you need to use AtomicBoolean in a lambda function?
body: <p>I have a remove method in my customList class that removes a an object passed as a parameter from from my customList object where contentInCustomList.equals(parameter) and returns a boolean indicating if anything was removed.<br>
  I am trying to implement a remove all method that takes a collection, performs the remove method for each member of the collection passing it as a parameter and returns a boolean indicating if anything was removed.<br>
  To do this, I initialized a boolean (toReturn) to false and made it so that, for each member of the collection, I'd change it (toReturn) to true if remove(i) or the boolean are true. This way, toReturn would stay true if it's been changed to true.<br></p>
  <pre class="lang-java prettyprint-override"><code>public boolean removeAll(@NotNull Collection c) {
      boolean toReturn = false;
      c.forEach(i -&gt;  toReturn = remove(i) || toReturn);
      return toReturn;
  }
  </code></pre>
  <p>However, when I try doing this, it gives me an error and intellliJ tells me to convert it to an AtomicBoolean:</p>
  <pre class="lang-java prettyprint-override"><code>public boolean removeAll(@NotNull Collection c) {
      AtomicBoolean toReturn = new AtomicBoolean(false);
      c.forEach(i -&gt; toReturn.set(toReturn.get() || remove(i)));
      return toReturn.get();
  }
  </code></pre>
  <p>Why does the first not work but the second does?</p>