What is the easiest way to iterate over all the key/value pairs of a java.util.Map in Java 5 and higher?

前端 未结 1 584
甜味超标
甜味超标 2021-02-11 15:02

What is the easiest way to iterate over all the key/value pairs of a java.util.Map in Java 5 and higher?

相关标签:
1条回答
  • 2021-02-11 15:48

    Assuming K is your key type and V is your value type:

    for (Map.Entry<K,V> entry : map.entrySet()) {
      K key = entry.getKey();
      V value = entry.getValue();
      // do stuff
    }
    
    0 讨论(0)
提交回复
热议问题