Entry

2019-06-27 19:57 更新

Entry 可以用于遍历Map,以HashMap为例:

HashMap<String, Integer> hashMap = new HashMap<>();
hashMap.put("a", 1);
hashMap.put("b", 2);
hashMap.put("c", 3);
Set<Entry<String, Integer>> eSet = hashMap.entrySet();
for(Entry<String, Integer> entry : eSet) {
    System.out.println(entry.getKey() + ": " + entry.getValue());
}
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号