Java Iterator toIterator(final T[] data)

Here you can find the source of toIterator(final T[] data)

Description

Creates an iterator over the supplied array.

License

Open Source License

Declaration

public static <T> Iterator<T> toIterator(final T[] data) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Iterator;

public class Main {
    /**// ww w .  j  a  va  2  s  . c o m
     * Creates an iterator over the supplied array. If the array is null, null is returned.
     */
    public static <T> Iterator<T> toIterator(final T[] data) {
        if (data == null) {
            return null;
        }
        return new Iterator<T>() {
            public boolean hasNext() {
                return (_index < data.length);
            }

            public T next() {
                return data[_index++];
            }

            public void remove() {
                throw new RuntimeException("remove() not possible");
            }

            protected int _index;
        };
    }
}

Related

  1. splice(LinkedList list, Iterator iterator, LinkedList list2, V v)
  2. toArray(final Iterator iterator)
  3. toCollection(final Iterator iterator, final Collection c)
  4. toCommaSeparatedString(Iterator i)
  5. toIterator(Collection col)
  6. toMap(final Iterator> iterator)
  7. toObjectIterator(Object[] objects)
  8. toSet(Iterator iteration)
  9. toString(Iterator iterObjects)