您将需要使迭代器成为有状态的。缓存您从中检索到的最后一个值,
hasNext并使用该
next方法中的值(如果存在)。
private boolean hasCached;private T cached;public boolean hasNext() { if ( hasCached ) return true; //iterate until you find one and set hasCached and cached}public T next() { if ( hasCached ) { hasCached = false; return cached; } //iterate until next matches}


