iterating over an integer array in java

Associate
Joined
6 Jan 2005
Posts
722
Location
colchester,essex
Hi,

At the moment im just doing a bit on stacks and how to code them using a stack.

I create the int arraylist and then try to iterate over the collection using the standard code.

It doesnt compile however.

Is there something special i need to do to allow me to iterate over an int[]

cheers
 
public class IStackImpl implements IStack {

private int[] items;
private int topPointer;

public IStackImpl(int maxsz){
items = new int[maxsz];
topPointer = 0;
}

public String toString() {
Iterator it = items.iterator();
while(it.hasNext()){
System.out.println(it.next());
}

}

Thats the code basically, ive imported the arraylist and iterator classes. The line its having a prob with is

Iterator it = items.iterator();

It says cannot find symbol

please help
 
iv sorted out the problem and i am working from a java book but its pretty poor tbh. Im at uni at the mo and am being taught java but the book leaves a lot of gaps.

Has anyone got any good recommendations.

The book i have at the moment is called "Objects first with java"
 
Back
Top Bottom