title: how hasnext() works in collection in java
body: <p>program:</p>
  
  <pre><code>public class SortedSet1 {
  
    public static void main(String[] args) {  
  
      List ac= new ArrayList();
  
      c.add(ac);
      ac.add(0,"hai");
      ac.add(1,"hw");
      ac.add(2,"ai"); 
      ac.add(3,"hi"); 
      ac.add("hai");
  
      Collections.sort(ac);
  
      Iterator it=ac.iterator();
  
      k=0;
  
      while(it.hasNext()) {    
        System.out.println(""+ac.get(k));
        k++;     
      }
    }
  }
  </code></pre>
  
  <p>output:
  ai
  hai
  hi
  hw
  hai</p>
  
  <p>how it execute 5 times??
  while come to hai no next element present so condition false. But how it executed.</p>