标签:
1、变量遍历键值对的三种方法:
public static void iterate1(Map<String, String> map) { Iterator<java.util.Map.Entry<String, String>> iterator = map.entrySet().iterator(); while (iterator.hasNext()) { java.util.Map.Entry<String, String> entry = iterator.next(); System.out.println(entry.getKey() + ":" + entry.getValue()); } } public static void iterate2(Map<String, String> map) { Set<String> set = map.keySet(); for (String key : set) { System.out.println(key + ":" + map.get(key)); } } public static void iterate3(Map<String,String> map){ Set<java.util.Map.Entry<String,String>> set= map.entrySet(); for (java.util.Map.Entry<String, String> entry : set) { System.out.println(entry.getKey()+":"+entry.getValue()); } }
2、只遍历值的一种方法
public static void iterate4(Map<String, String> map) { for (String value : map.values()) { System.out.println(value); } }
标签:
原文地址:http://www.cnblogs.com/zhisuoyu/p/5247516.html