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()); }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-11-12 05:41:41