package com.hashmap.test;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
public class HashMapTest {
public static void main(String[] args) {
HashMap<String, String> kmap = new HashMap<String, String>();
// 装数据
for (int i = 0; i < 10000; i++) {
kmap.put("" + i, "test");
}
long start1 = System.currentTimeMillis();
Iterator<String> ktor = kmap.keySet().iterator();
while (ktor.hasNext()) {
System.out.print(kmap.get(ktor.next()));
}
System.out.println();
System.out.println("KeySetTime = "
+ (System.currentTimeMillis() - start1));
long start2 = System.currentTimeMillis();
Iterator<Entry<String, String>> itor = kmap.entrySet().iterator();
while (itor.hasNext()) {
Entry<String, String> e = itor.next();
System.out.print(e.getValue());
}
System.out.println();
System.out.println("EntrySetTime = "
+ (System.currentTimeMillis() - start2));
}
}
结果 : KeySetTime = 46
EntrySetTime = 30