I have something like:
Map<Integer, String> topology = new TreeMap<Integer, String>();
Which contains for example:
01, my.vm.01.serv.com
04, my.vm.04.serv.com
07, my.vm.07.serv.com
08, my.vm.08.serv.com
09, my.vm.09.serv.com
I'd like to be able to say "I have key 07
, get me the next key in the map from this point", which would ideally return 08
.
Is there a way to do this without using an iterator?
"I have key 07, get me the next key in the map from this point",
If you do not want to change the definition of Map
, you could try something like
List<Integer> keys = new ArrayList<Integer>(topology.keySet());
Integer integer = keys.get((keys.indexOf(7))+1); // next key
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With