package cn.jiguang.base64;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.junit.Test;
public class CollectionTest {
public void JDK8DataTimeClockTest() {
}
@Test
public void foreachQuery() {
int count = 0;
Map<String, String> map = new HashMap<String, String>();
for (int i = 0; i < 100000; i++) {
map.put("key=" + i, "value=" + i);
}
long startTimeFor = System.currentTimeMillis();
for (Entry<String, String> entry : map.entrySet()) {
System.out.println(entry.getKey());
System.out.println(entry.getValue());
count++;
}
System.out.println("查询记录数=" + count);
System.out.println("增强for查询耗时:" + (startTimeFor - System.currentTimeMillis()));
}
@Test
public void iteratorQuery() {
int count = 0;
Map<String, String> map = new HashMap<String, String>();
for (int i = 0; i < 1000000; i++) {
map.put("key=" + i, "value=" + i);
}
Iterator<Entry<String, String>> iterator = map.entrySet().iterator();
long startTimeIterator = System.currentTimeMillis();
while (iterator.hasNext()) {
String key = iterator.next().getKey();
String value = iterator.next().getValue();
System.out.println(key);
System.out.println(value);
count++;
}
System.out.println("查询记录数=" + count);
System.out.println("迭代器Iterator查询耗时:" + (startTimeIterator - System.currentTimeMillis()));
}
}