title: For-Each Loop Alternative - Clarification
body: <p>I am working through lessons in Java, and have not been able to completely understand what is going on in the following lesson.</p>
  
  <p>Purpose: The purpose of this lesson is to explain how a for-each loop works by creating an alternative that simulates how the for-each loop would work.</p>
  
  <p>In the previous lesson, the explanation of the for-each loop was simple:</p>
  
  <pre><code>import java.util.ArrayList //Imports ArrayList CLASS
  
  public class ForEachLoops
  
  {
  
      public static void main(String[] args)
      {
  
          ArrayList&lt;Integer&gt; numbers = new ArrayList&lt;Integer&gt;(); 
          // ^ Creates ArrayList object &amp; calls constructor
          for(int i = 1; i &lt; 11; ++i)
              numbers.add(i); //Just adding numbers 1-10 to the ArrayList.
  
  
          for(int n : numbers) //For-Each Loop
              System.out.println(n); //Returns value from each ArrayList element
  
  
      }
  
  }
  </code></pre>
  
  <p>In the next lesson, the instructor was showing how to create an alternative/simulator of the for-each loop. It works as follows:</p>
  
  <pre><code>import java.util.ArrayList; //Importing ArrayList class from package
  import java.util.Iterator; // Question 1 (See Below)
  
  public class Chap16Part9
  {
  
      public static void main(String[] args)
      {
  
          ArrayList&lt;Integer&gt; numbers = new ArrayList&lt;Integer&gt;();
          // ^ Creating object of ArrayList &amp; calling constructor
  
          for(int i = 1; i &lt; 11; ++i)
              numbers.add(i); //Just adding numbers 1-10 to ArrayList object
  
          for(Iterator&lt;Integer&gt; n = numbers.iterator(); n.hasNext();) {
     //       ^ Question 2 (See Below)
              int num = n.next(); //Points to the next element to assign value.
              System.out.println(num); //Prints current value of "num."
          }
  
      }
  
  }
  </code></pre>
  
  <p><strong>Question 1</strong>: After reading the Java documentation, "Iterator" is listed as an interface. Is this still the same as importing a class? For example, in the Java documentation, "java.util.Scanner" is considered a class, and not an interface.</p>
  
  <p><strong>Question 2</strong>: Before asking the question, the loop does not need a "++i" type of control implemented because the hasNext() method of the Iterator checks to see if there is another element to check. If not, then it stop. It's a boolean value. The beginning of the loop, however, the loop-control variable (LCV) is "<code>Iterator&lt;Integer&gt; n = numbers.iterator();</code>" and I am not quite understand what is meant by this. In my eyes, I see an object of the Iterator class? being set equal to the ArrayList iterator() method. Could it be because given that "java.util.Interator;" is considered an interface (basically a contract that has declared methods that must be implemented if it is implemented by a class), the ArrayList class completes the set of statements of the declared iterator() methods in the ArrayList class and, therefore, needs to be called that way instead of by a constructor as traditional classes are called (the ArrayList, for example)? I am a bit confused by this, and I am hoping somebody can shed light on this. Thank you!</p>