tags:

views:

153

answers:

4

greetings all i am using an Iterator to iterate through collection and i want to get the current loop index any ideas how to do that ?

+1  A: 

Use an int and increment it within your loop.

Florian Reischl
+6  A: 

Use your own variable an increment it in the loop.

Chris Diver
+1  A: 

What kind of collection? If it's an implementation of the List interface then you could just use (it.nextIndex()-1).

Zenzen
A: 

Use a ListIterator to iterate through the Collection. If the Collection is not a List to start with use Arrays.asList(Collection.toArray()) to turn it into a List first.

Jatin