package gather; import java.util.HashMap; public class TestOne { public static void main(String[] args) { HashMap<String, String> map = new HashMap<String, String>(); map.put("k1", "v1"); map.put("k2", "v2"); map.put("k3", "v3"); /* Iterator<Entry<String, String>> iterator2 = map.entrySet().iterator(); while(iterator2.hasNext()){ Entry<String, String>entry = iterator2.next(); System.out.println(entry.getKey()); System.out.println(entry.getValue()); } Iterator<String> iterator = map.keySet().iterator(); while(iterator.hasNext()){ System.out.println(iterator.next()); } */ /* * 增强型for * for ( Entry<String, String> entry : map.entrySet()) { System.out.println(entry.getKey()); System.out.println(entry.getValue()); } for ( String entry : map.keySet()) { System.out.println(entry); } */ } }
http://www.trinea.cn/android/hashmap-loop-performance/