How can I repeat this card in the opposite direction

This is my map with iterators to delete some data based on some conditions, now I want to run the same map in the opposite direction and conditions, respectively.

But I could not find ListIterator to return easily.

How can i do this?

Also the Map implementation that I use is TreeMap

 for(int i=countIteration;i<(countIteration+2);i++) { Iterator it = imageFilexxSm.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry)it.next(); if(pairs.getKey().equals(data1.get(i).replace(".png", ".mp3"))) { it.remove(); } } Iterator itr = imageFilexxS.entrySet().iterator(); while (itr.hasNext()) { Map.Entry pairsx = (Map.Entry)itr.next(); if(pairsx.getKey().equals(data1.get(i))) { System.out.println("entry deleted."+pairsx.getKey()); itr.remove(); } } } 
+4
source share
1 answer

TreeMap has a descendingMap method (note that it returns a view on the original map, it does not copy it):

 //iterate over the entry set in reverse order for (Map.Entry<X,Y> e : map.descendingMap().entrySet()) { X key = e.getKey(); Y value = e.getValue(); } 
+16
source

Source: https://habr.com/ru/post/1480719/


All Articles