@Test public void testFromArray() { Iterator<Integer> it = Iterables.fromArray(new Integer[] { 1, 2 }).iterator(); assertTrue(it.hasNext()); assertEquals(1, (int) it.next()); assertTrue(it.hasNext()); assertEquals(2, (int) it.next()); assertFalse(it.hasNext()); }
public static <T> Iterable<T> fromArray(T[] array) { return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { int i = 0; @Override public boolean hasNext() { return i < array.length; } @Override public T next() { i++; if (i > array.length) { throw new NoSuchElementException(); } else { return array[i - 1]; } } }; } }; }
Iterables { public static <T> Iterable<T> fromArray(T[] array) { return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { int i = 0; @Override public boolean hasNext() { return i < array.length; } @Override public T next() { i++; if (i > array.length) { throw new NoSuchElementException(); } else { return array[i - 1]; } } }; } }; } }
Iterables { public static <T> Iterable<T> fromArray(T[] array) { return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { int i = 0; @Override public boolean hasNext() { return i < array.length; } @Override public T next() { i++; if (i > array.length) { throw new NoSuchElementException(); } else { return array[i - 1]; } } }; } }; } private  Iterables(); }
Iterables { public static <T> Iterable<T> fromArray(T[] array) { return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { int i = 0; @Override public boolean hasNext() { return i < array.length; } @Override public T next() { i++; if (i > array.length) { throw new NoSuchElementException(); } else { return array[i - 1]; } } }; } }; } private  Iterables(); static Iterable<T> fromArray(T[] array); @SafeVarargs static Iterable<T> ofNoCopy(T... values); }
Iterables { public static <T> Iterable<T> fromArray(T[] array) { return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { int i = 0; @Override public boolean hasNext() { return i < array.length; } @Override public T next() { i++; if (i > array.length) { throw new NoSuchElementException(); } else { return array[i - 1]; } } }; } }; } private  Iterables(); static Iterable<T> fromArray(T[] array); @SafeVarargs static Iterable<T> ofNoCopy(T... values);  }