*/
import java.util.*; class Demo { public static void main(String[] args) { HashMap<String,String> map = new HashMap<String,String>(); map.put("001","zhangsan"); map.put("002","xuzhong"); map.put("003","lisi"); //使用 entrySet()遍历集合 Set<Map.Entry<String,String>> entry = map.entrySet(); Iterator<Map.Entry<String,String>> ite = entry.iterator(); while(ite.hasNext()) { Map.Entry<String,String> en = ite.next(); String key = en.getKey(); String value = en.getValue(); sop(key+"=="+value); } //使用keySet()遍历 /* Set<String> keys = map.keySet(); Iterator<String> ite = keys.iterator(); while(ite.hasNext()) { String key = ite.next(); String value = map.get(key); sop(key+"=="+value); } */ } public static void sop(Object obj) { System.out.println(obj); } }
原文地址:http://blog.csdn.net/u011007829/article/details/43234157