title: How to best clear a variable in a lot of objects?
body: <p>If I want to clear a specific boolean variable on a lot of objects, and one of these objects should get this variable set afterwards, what is most efficient:</p>
  
  <ul>
  <li>iterate all objects and just set the var = false</li>
  <li>iterate all objects, check the var and just set it false for the one that where true</li>
  </ul>
  
  <blockquote>
  <pre><code>class Foo {
     boolean bar;  //false for most objects
  }
  </code></pre>
  </blockquote>
  
  <p>Then either use:</p>
  
  <pre><code>for (Foo foo : fooList) {
     foo.setBar(false);
  }
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>for (Foo foo : fooList) {
      if (foo.isBar()) {
         foo.setBar(false);
      }
  }
  </code></pre>
  
  <p>then set one foo:</p>
  
  <pre><code>singleFoo.setBar(true);
  </code></pre>
  
  <p>Probably the time saving is minor for both implementations. But I cannot measure that atm, so I'd be interested what you thing is the better approach?</p>