Here you can find the source of searchIndexInIterator(Iterator
public static <T> int searchIndexInIterator(Iterator<T> iterator, T value)
//package com.java2s; //License from project: Open Source License import java.util.Iterator; public class Main { public static <T> int searchIndexInIterator(Iterator<T> iterator, T value) { return searchIndexInIterator(iterator, value, 0); }/*from w w w . j a v a2s . c o m*/ public static <T> int searchIndexInIterator(Iterator<T> iterator, T value, int startIndex) { int expectedHashCode = value == null ? 0 : value.hashCode(); for (int i = 0; i < startIndex && iterator.hasNext(); i++) { iterator.next(); } if (!iterator.hasNext()) { return -1; } for (int i = startIndex; iterator.hasNext(); i++) { T next = iterator.next(); if (next == null) { if (value == null) { return i; } else { continue; } } else if (value == null) { continue; } if (next.hashCode() == expectedHashCode && next.equals(value)) { return i; } } return -1; } }