Search code examples
javascalaiteratorbidirectional

Bidirectionnal iterator over a TreeMap[A,B]


Is there a way to get a bidirectionnal iterator over a TreeMap, ie an iterator[(A,B)] with hasPrevious, previous methods completing the hasNext, next methods ?

I know it does not exists natively in scala but I have some hope some trick could make it possible via some java adapters/facade/wrappers.


Solution

  • TreeMap provides the navigableKeySet() method which returns a NavigableSet which provides a descendingIterator().

    Not certain how you would work with that in Scala though.