Iterator has .next() - is there a way to get the previous element instead of the next one?

后端 未结 10 664
离开以前
离开以前 2020-12-11 00:46

I have an Iterator that I use on a HashMap, and I save and load the iterator. is there a way to get the previous key in the HashMap with Iterator? (java.util.Iterator)

10条回答
  •  再見小時候
    2020-12-11 01:07

    As others have said, you only access an element using next(). However it's sort of a matter of terminology. Once you call next() this is the current element.

    Unless the problem is you need to see two consecutive items in the collection each iteration, in which case a simple variable would seem easiest.

提交回复
热议问题