How to get the previous key/value and the next key/value in Maps

前端 未结 2 1174
陌清茗
陌清茗 2020-12-09 06:04
for (Entry entry : map.entrySet()) { 
        Double key = entry.getKey(); 
        String value = entry.getValue(); 

        // double nextKe         


        
2条回答
  •  情书的邮戳
    2020-12-09 06:31

    A TreeMap is an OrderedMap and a NavigableMap and will allow you to iterate forward and backward, allowing you to access previous and next keys with lowerKey() and higherKey() respectively. However it might not be the best solution.

    Can you describe the actual problem you're trying to solve, and we can give you a more fitting solution?

提交回复
热议问题