Advances iterator position + 1 times, returning the element at the positionth position. @param position position of the element to return @return the element at the specified position in iterator @throws IndexOutOfBoundsException if position is negative or
(Iterator<T> iterator, int position)
| 811 | |
| 812 | |
| 813 | public static <T> T get(Iterator<T> iterator, int position) { |
| 814 | checkNonnegative(position); |
| 815 | int skipped = advance(iterator, position); |
| 816 | if (!iterator.hasNext()) { |
| 817 | throw new IndexOutOfBoundsException("position (" + position |
| 818 | + ") must be less than the number of elements that remained (" |
| 819 | + skipped |
| 820 | + ")"); |
| 821 | } |
| 822 | return iterator.next(); |
| 823 | } |
| 824 | |
| 825 | |
| 826 | static void checkNonnegative(int position) { |