Iterator problem, using arrays

Posted on 2006-05-08
Last Modified: 2013-12-29
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) {
      return true;
      return false;
  public boolean add( T x ) {
      return true;
      return false;
  public boolean remove(Object x) {
    if(bst.find((T)x) != x)
    return true;
      return false;
  public T get( int i ) throws NoSuchElementException {
        return bst.findKth(i);
  public int indexOf( Object obj ) {
      return bst.indexOf((T)obj);
      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() {
  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())
Question by:no158
    LVL 14

    Expert Comment

    > iter.current

    Iterator does not have such filed
    LVL 17

    Assisted Solution

    Hi no158,

    Did you mean:

    Joe P
    LVL 14

    Expert Comment

    > new v.iterator();
    eliminate new keyword
    LVL 14

    Accepted Solution

    Iterator iter = v.iterator();

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Hire Top Freelancers to Complete Java Projects

    Source the talented Expert Exchange community
    for top quality work on your Java projects.

    Hire the best. Collaborate easily. Get quality work.

    Suggested Solutions

    Title # Comments Views Activity
    Understanding @ResponseBody annotation 5 36
    mergeTwo  challenge 13 53
    Enhanced For loop vs ForEach Loop 4 42
    array11 challenge 16 40
    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    This video teaches viewers about errors in exception handling.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now