Here you can find the source of getFrom(Iterable
@SuppressWarnings("unchecked") public static <T> T getFrom(Iterable<T> iterable, int index) throws IndexOutOfBoundsException
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.List; public class Main { @SuppressWarnings("unchecked") public static <T> T getFrom(Iterable<T> iterable, int index) throws IndexOutOfBoundsException { //could throw IndexOutOfBoundsException if (iterable instanceof List<?>) { return (T) ((List<?>) iterable).get(index); }//from w w w. j a va 2 s . co m return elementAt(iterable, index); } public static <T> T elementAt(Iterable<T> iterable, int index) { checkIndex(iterable, index); int currIndex = 0; T out = null; for (T obj : iterable) { if (currIndex == index) { out = obj; break; } ++currIndex; } return out; } public static <T> void checkIndex(Iterable<T> iterable, int index) { if (index > sizeOf(iterable) - 1 || index < 0) { throw new IndexOutOfBoundsException("Index " + index + " is out of the bounds of " + iterable); } } public static int sizeOf(Iterable<?> iterable) { if (iterable instanceof Collection<?>) { return ((Collection<?>) iterable).size(); } int size = 0; for (@SuppressWarnings("unused") Object o : iterable) { ++size; } return size; } }