title: Iterator in Java
body: <p>What is Iterator and collections? 
  Does these two have any relations?</p>
  
  <pre><code>// the interface definition
  Interface Iterator {
      boolean hasNext();
      Object next(); // note "one-way" traffic
      void remove();
  }
  
  // an example
  public static void main (String[] args){
      ArrayList cars = new ArrayList();
  
      for (int i = 0; i &lt; 12; i++)
          cars.add (new Car());
  
      Iterator it = cats.iterator();
  
      while (it.hasNext())
          System.out.println ((Car)it.next());
  }
  </code></pre>
  
  <p>Does the Interface Iterator has these method names alone predefined or its user defined?.
  What does these four lines below actually tell?</p>
  
  <pre><code>cars.add (new Car());
  Iterator it = cats.iterator();
  while (it.hasNext())
      System.out.println ((Car)it.next());
  </code></pre>
  
  <p>Thanks. I am going through a book in collections.</p>