Java examples for Collection Framework:Iterator
Converts an array to an iterator of objects.
//package com.java2s; import java.lang.reflect.Array; import java.util.Iterator; public class Main { /**/*from w ww .j a v a2 s. c o m*/ * Converts an array to an iterator of objects. */ public static Iterator<Object> toIteratorArray(final Object array) { final int length = Array.getLength(array); return new Iterator<Object>() { int index = 0; @Override public boolean hasNext() { return index < length; } @Override public Object next() { return Array.get(array, index++); } @Override public void remove() { } }; } }