阅读目录
遍历
Map map = new HashMap(); Iterator iter = map.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); Object key = entry.getKey(); Object val = entry.getValue();
例
import java.util.HashMap; import java.util.Iterator; import java.util.Map; public class testMap { public static void main(String[] args){ testMap test = new testMap(); HashMap map = new HashMap<String, String>(); map.put("a", "123"); map.put("a", "456"); map.put("b", "789"); test.transMap(map); } void transMap(HashMap map){ Iterator iter = map.entrySet().iterator(); while(iter.hasNext()){ Map.Entry entry =(Map.Entry)iter.next(); Object key = entry.getKey(); Object val = entry.getValue(); System.out.println((String)key + ":" + (String)val); } } }
输出
a:456
b:789
dd
本文转自jihite博客园博客,原文链接:http://www.cnblogs.com/kaituorensheng/p/5840842.html,如需转载请自行联系原作者