title: IntelliJ suggests replacing the while loop with a for each loop. Why?
body: <pre><code>    ArrayList&lt;Object&gt; list = new ArrayList&lt;Object&gt;();
      list.add(12);
      list.add("Hello");
      list.add(true);
      list.add('c');
  
      Iterator iterator = list.iterator();
      while(iterator.hasNext())
      {
          System.out.println(iterator.next().toString());
      }
  </code></pre>
  
  <p>When I enter this Java code in IntelliJ IDEA, the code analysis feature suggests that I replace the while loop with a for each loop since I'm iterating on a collection. Why is this?</p>