Iterator problem, using arrays

I'm trying to creat a main method that will crate an array with size 5 the values of the elements are {4, 7, 3, 0, 1}.
This next part i'm getting a little confused about. I'm trying to creat an iterator for the array and print the array using the iterator.

The errors i'm getting are:
2 Errors found:
Error(1): package v does not exist  ---------->( found on this line  [Iterator iter = new v.iterator();] )
Error(2): cannot find symbol  ---------------->( found on this line   [System.out.println(iter.current);] )
symbol  : variable current
location: interface java.util.Iterator

import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.AbstractCollection;

public class BSTOrderedList<T extends Comparable<? super T>>
  extends AbstractCollection<T>
  implements OrderedList<T> {
 
  private BinarySearchTreeWithRank<T> bst = new BinarySearchTreeWithRank<T>();
 
  public BSTOrderedList() {
  }
 
  public int size() {
    return bst.size();
  }
 
  public boolean contains(Object x) {
    if(bst.find((T)x).equals(x))
      return true;
    else
      return false;
  }
 
  public boolean add( T x ) {
    bst.insert(x);
    if(bst.find(x).equals(x))
      return true;
    else
      return false;
  }
 
  public boolean remove(Object x) {
    bst.remove((T)x);
    if(bst.find((T)x) != x)
    return true;
    else
      return false;
  }
 
  public T get( int i ) throws NoSuchElementException {
        return bst.findKth(i);
  }
 
  public int indexOf( Object obj ) {
    if(bst.find((T)obj).equals(obj))
      return bst.indexOf((T)obj);
    else
      return -1;
  }
 
  public Iterator<T> iterator() {
    MyIterator iter = new MyIterator();
    return iter;
  }
 
  private class MyIterator implements Iterator {
     private Comparable current;
     private int k;
     
     public MyIterator() {
          current = bst.findKth(++k);
     }
     
     public boolean hasNext() {
          return bst.findKth(k + 1) != null;
     }
     
     public Comparable next() {
       return (current = bst.findKth(++k));
     }
     
     public void remove() {
       bst.remove((T)current);
     }
   
  }
 
  public static void main(String[] args) {

    int[] arr = {4, 7, 3, 0, 1};
   
  BSTOrderedList v = new BSTOrderedList();
  Iterator iter = new v.iterator();
 
while( iter.hasNext())
  System.out.println(iter.current);
  }
}
no158Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hoomanvCommented:
> iter.current

Iterator does not have such filed
0
BogoJokerCommented:
Hi no158,

Did you mean:
System.out.println(iter.next());

Joe P
0
hoomanvCommented:
> new v.iterator();
eliminate new keyword
0
hoomanvCommented:
Iterator iter = v.iterator();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.