您可以通过调用来遍历键,也可以通过调用来
map.keySet()遍历项
map.entrySet()。遍历条目可能会更快。
for (Map.Entry<String, List<String>> entry : map.entrySet()) { List<String> list = entry.getValue(); // Do things with the list}如果要确保按插入键的顺序遍历键,请使用
linkedHashMap。
顺便说一句,我建议将地图的声明类型更改为
<String, List<String>>。始终最好根据接口而不是实现来声明类型。



