Map<String, String> map = new HashMap<String, String>(); for(int i=0;i<100;i++){ map.put(i+"", i+""); } //遍历值 System.out.println("遍历值"); for(String value : map.values()){ System.out.println(value); } //遍历键 System.out.println("遍历键"); for(String key:map.keySet()){ System.out.println(key+":"+map.get(key)); } //通过迭代器 System.out.println("通过迭代器"); Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator(); while(iterator.hasNext()){ Map.Entry<String, String> entry = iterator.next(); System.out.println(entry.getKey()+":"+entry.getValue()); } //entrySet遍历 System.out.println("entrySet"); for(Map.Entry<String, String> entry:map.entrySet()){ System.out.println(entry.getKey()+":"+entry.getValue()); }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/qq_22605739/article/details/47316153