title: Java Iterator going in infinite while loop
body: <p>I am trying to iterate list with the <code>iterator</code> in while, for some reason its going in infinite.</p>
  
  <p>here is the code</p>
  
  <pre><code>{
  List&lt;Person&gt; Person1 = new ArrayList&lt;Person&gt;();
  
      Person p1 = new Person("Name1", "Virginia");
  
      Person1.add(new Person("Nae2", "Virginia"));
  
      printerlist(Person1);
  
      printerlist(p1);
  
  }
  
  private static void printerlist(List&lt;Person&gt; p) {
  
      /*
       * print the list
       */
      while (p.iterator().hasNext()) {
          System.out.println(p.iterator().next().getCity());
      }
  
  }
  </code></pre>