java中map的循环
public class MyUtils {
public static void main(String[] args) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("aaa", 111);
map.put("bbb", 222);
map.put("ccc", 333);
map.put("ddd", 444);
//Map集合循环遍历方式一
System.out.println("第一种:通过Map.keySet()遍历key和value:");
for(String key:map.keySet()){//keySet获取map集合key的集合 然后在遍历key即可
String value = map.get(key).toString();//
System.out.println("key:"+key+" vlaue:"+value);
}
//Map集合循环遍历二 通过迭代器的方式
System.out.println("第二种:通过Map.entrySet使用iterator遍历key和value:");
Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator();
while(it.hasNext()){
Map.Entry<String, Object> entry