objectarrayiterator.java
来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 60 行
JAVA
60 行
/*
* $Id: ObjectArrayIterator.java,v 1.1 2003/11/25 11:41:47 epr Exp $
*/
package org.jnode.util;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* @author epr
*/
public class ObjectArrayIterator implements Iterator {
private final Object[] array;
private final int max;
private int index;
/**
* Initialize a new instance
* @param array
*/
public ObjectArrayIterator(Object[] array) {
this.array = array;
if (array == null) {
max = 0;
} else {
max = array.length;
}
}
/**
* @see java.util.Iterator#hasNext()
* @return boolean
*/
public boolean hasNext() {
return (index < max);
}
/**
* @see java.util.Iterator#next()
* @return Object
*/
public Object next() {
if (index < max) {
final Object result = array[index];
index++;
return result;
} else {
throw new NoSuchElementException();
}
}
/**
* @see java.util.Iterator#remove()
*/
public void remove() {
throw new UnsupportedOperationException();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?