62,614
社区成员
发帖
与我相关
我的任务
分享
public class ArrayIterator<T> {
private T[] contents;
private int count;
private int i = 0;
public ArrayIterator(T[] contents, int count) {
this.contents = contents;
this.count = count;
}
public boolean hasNext() {
if (i < count)
return true;
else
return false;
}
public T next() {
return contents[i++];
}
public static void main(String[] args) {
Integer[] a = { 1, 2, 3, 4, 5, 6 };
ArrayIterator<Integer> ai = new ArrayIterator<Integer>(a, a.length);
for (Integer i : a) {
System.out.println(ai.next());
}
}
}
class M
{
public static void main(String[] args)
{
Integer[] a = {1,2,3,4,5,6};
ArrayIterator<Integer> ai = new ArrayIterator<Integer>(a,a.length);
}
}