static L lazyListFromIterator(Iterator it) { ret new RandomAccessAbstractList() { new L list; public int size() { realizeFully(); ret list.size(); } public A get(int i) { realizeUpTo(i); ret list.get(i); } void realizeUpTo(int i) { while (i >= list.size() && it.hasNext()) list.add(it.next()); } void realizeFully() { realizeUpTo(Int.MAX_VALUE); } }; }