3 回答

TA贡献1816条经验 获得超4个赞
还有另一种方式。
鉴于您编写自己的Index类和静态方法,可以返回Iterable此类的实例
for (Index<String> each: With.index(stringArray)) {
each.value;
each.index;
...
}
执行的地方With.index是什么样的
class With {
public static <T> Iterable<Index<T>> index(final T[] array) {
return new Iterable<Index<T>>() {
public Iterator<Index<T>> iterator() {
return new Iterator<Index<T>>() {
index = 0;
public boolean hasNext() { return index < array.size }
public Index<T> next() { return new Index(array[index], index++); }
...
}
}
}
}
}
添加回答
举报