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

后端 未结 10 682
离开以前
离开以前 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:26

    Make your own Iterator:

    public class EnhancedIterator implements Iterator{
        private List list;
        private int indexSelected=-1;
        public EnhancedIterator(List list){
            this.list=list;
        }
    
        @Override
        public boolean hasNext() {
            return indexSelected

提交回复
热议问题