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)
| 766 | * {@code iterator} |
| 767 | */ |
| 768 | public static <T> T get(Iterator<T> iterator, int position) { |
| 769 | checkNonnegative(position); |
| 770 | int skipped = advance(iterator, position); |
| 771 | if (!iterator.hasNext()) { |
| 772 | throw new IndexOutOfBoundsException( |
| 773 | "position (" |
| 774 | + position |
| 775 | + ") must be less than the number of elements that remained (" |
| 776 | + skipped |
| 777 | + ")"); |
| 778 | } |
| 779 | return iterator.next(); |
| 780 | } |
| 781 | |
| 782 | static void checkNonnegative(int position) { |
| 783 | if (position < 0) { |