Java Array to Iterable toIterable(final T[] arr)

Here you can find the source of toIterable(final T[] arr)

Description

to Iterable

License

Apache License

Declaration

public static <T> Iterable<T> toIterable(final T[] arr) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    public static <T> Iterable<T> toIterable(final T[] arr) {
        return new Iterable<T>() {
            @Override//from  w  ww .j  a  va  2 s  .  co m
            public Iterator<T> iterator() {
                return new Iterator<T>() {
                    int index = 0;

                    @Override
                    public boolean hasNext() {
                        return index < arr.length;
                    }

                    @Override
                    public T next() {
                        return arr[index++];
                    }

                    @Override
                    public void remove() {
                        throw new RuntimeException("Not supported");
                    }
                };
            }
        };
    }
}

Related

  1. toIterable(final boolean[] values)
  2. toIterable(final T[] array)