title: Interface Iterator already defined somewhere in Java?
body: <p>Is the interface <code>Iterator</code> already defined somewhere in java library (mind the terminology).
  i.e.</p>
  
  <p>What i am asking is that, say i have an arraylist, now i write.</p>
  
  <pre><code>Iterator itr= new Iterator();
  </code></pre>
  
  <p>but i never define anything like</p>
  
  <pre><code>public interface Iterator{  // all the methods };
  </code></pre>
  
  <p>Do i need to import some package where this iterator is already defined?</p>
  
  <p>Let me take an example here:</p>
  
  <pre><code>class BOX implements Comparable {
  
      private double length;
      private double width;
      private double height;
  
      BOX(double l, double b, double h) {
          length = l;
          width = b;
          height = h;
      }
  
      public double getLength() {
          return length;
      }
  
      public double getWidth() {
          return width;
      }
  
      public double getHeight() {
          return height;
      }
  
      public double getArea() {
          return 2 * (length * width + width * height + height * length);
      }
  
      public double getVolume() {
          return length * width * height;
      }
  
      public int compareTo(Object other) {
          BOX b1 = (BOX) other;
          if (this.getVolume() &gt; b1.getVolume()) {
              return 1;
          }
          if (this.getVolume() &lt; b1.getVolume()) {
              return -1;
          }
          return 0;
      }
  
      public String toString() {
          return 
          “Length:
          ”+length +
          ” Width:
          ”+width +
          ” Height:
          ”+height;
      }
  } // End of BOX class
  </code></pre>
  
  <p>And here is my test class.</p>
  
  <pre><code>import java.util.*;
  
  class ComparableTest {
  
      public static void main(String[] args) {
          ArrayList box = new ArrayList();
          box.add(new BOX(10, 8, 6));
          box.add(new BOX(5, 10, 5));
          box.add(new BOX(8, 8, 8));
          box.add(new BOX(10, 20, 30));
          box.add(new BOX(1, 2, 3));
          Collections.sort(box);
          Iterator itr = ar.iterator();
          while (itr.hasNext()) {
              BOX b = (BOX) itr.next();
              System.out.println(b);
          }
      }
  }// End of class
  </code></pre>
  
  <p>Now in class <code>ComparableTest</code>  should not it implement <code>interface iterator</code>  also, shall i not define an <code>interface iterator</code> that will contain all the methods. Also, where is the implementation of the iterator methods are?</p>
  
  <p>I maybe confused alot, but kindly help!
  thanks.</p>