Here you can find the source of getObjectAtIteratorPos(Iterator> i, int pos)
Parameter | Description |
---|---|
i | The Iterator to be cycled through. |
pos | The numeric position of the Object to be returned |
public static Object getObjectAtIteratorPos(Iterator<?> i, int pos) throws ArrayIndexOutOfBoundsException
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**/*from w w w . j a v a2 s . com*/ * Given a numeric position, cycle through the given Iterator until the position * is reached, and return the Object found there. * * @param i The Iterator to be cycled through. * @param pos The numeric position of the Object to be returned * @return The Object at the indicated position */ public static Object getObjectAtIteratorPos(Iterator<?> i, int pos) throws ArrayIndexOutOfBoundsException { int currPos = 0; Object oc; while (i.hasNext()) { oc = i.next(); if (currPos == pos) return oc; else currPos++; } throw new ArrayIndexOutOfBoundsException(); } }