Take the 2-minute tour ×

Guava's AbstractLinkedIterator class

seems to exist to allow for restarting an iteration in the middle of something like a LinkedHashMap. But I'm failing to find any classes in guava that ever return this. Is there, in fact, a way to iterate a LinkedHashMap or a LinkedHashMultimap via a subclass of one of these?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

This link says there are no uses as yet (02/05/2011) and i certainly couldn't find any either. Looking at the source code this is a very skeletal implementation which just calls down to it's inheritors to ask them what the next might be based on the current element but you'd have to implement the meat of it yourself (which might indeed give you your Iterators that can start from any point in some ordered set/list). What is it you're trying to do?

share|improve this answer
I want to have a large linked hash table and allow a web service to 'curse' through it, retrieving blocks of key/value pairs in order. –  bmargulies May 2 '11 at 21:13
@bmargulies: Just use the Iterator for the entrySet() of the LinkedHashMap... it does have access to the internals and if you stop iterating at some point and then start iterating again (using the same Iterator) it'll continue from the entry it was at. –  ColinD May 2 '11 at 21:24
I don't have anyplace to keep such an iterator around in between calls to a service that has no per-client state. I found an alternative in fastutil that's a little better. –  bmargulies May 2 '11 at 23:55

AbstractLinkedIterator, as its Javadoc states:

provides a skeletal implementation of the Iterator interface for sequences whose next element can always be derived from the previous element.

That's all it's for. It doesn't have any knowledge of, say, a current linked entry in in a LinkedHashMap. If you had access to the nodes of a linked structure and you made this an Iterator<Node> you could of course compute the next node from the previous one, but LinkedHashMap doesn't expose its linked entries.

share|improve this answer

AbstractLinkedIterator is very useful for creating Iterators and Iterables that represent reccurances - e.g. potentially infinite Iterable with prime numbers etc.

If you need to restart the iteration, just use the Iterable to create new Iterator.

share|improve this answer

Your Answer


