80,428
社区成员
发帖
与我相关
我的任务
分享
Map map = new HashMap();
Iterator iter = map.keySet().iterator();
while (iter.hasNext()) {
Object key = iter.next();
Object val = map.get(key);
}
Map map = new HashMap();
Iterator iter = map.keySet().iterator();
while (iter.hasNext()) {
Object key = iter.next();
Object val = map.get(key);
}
import java.io.ObjectInputStream.GetField;
import java.util.HashMap;
import java.util.Iterator;
/**
* @Title: test.java
* @Package
* @Description: TODO(用一句话描述该文件做什么)
* @author no47wk lotp,Come back
* @date 2012-7-14 上午11:02:23
* @version V1.0
*/
/**
* @ClassName: test
* @Description: TODO(这里用一句话描述这个类的作用)
* @author no47wk lotp,Come back
* @date 2012-7-14 上午11:02:23
*/
public class test {
public static void main(String[] args) {
test t=new test();
t.KeySet();
t.EntrySet();
}
private void KeySet() {
HashMap<String, String> map = getData();
Iterator<String> ite = map.keySet().iterator();
long start = System.currentTimeMillis();
while (ite.hasNext()) {
map.get(ite.next());
}
long end = System.currentTimeMillis();
long time = end - start;
System.out.println("KeySet " + time + "");
}
private void EntrySet() {
HashMap<String, String> map = getData();
Iterator<java.util.Map.Entry<String, String>> ite = map.entrySet()
.iterator();
java.util.Map.Entry<String, String> entry;
long start = System.currentTimeMillis();
while (ite.hasNext()) {
entry = ite.next();
entry.getKey();
entry.getValue();
}
long end = System.currentTimeMillis();
long time = end - start;
System.out.println("EntrySet " + time + "");
}
private HashMap<String, String> getData() {
HashMap<String, String> ret = new HashMap<String, String>();
int i = 0;
while (i < 10000000) {
ret.put(String.valueOf(i), "a");
i++;
}
return ret;
}
}
/**
* @Title: Test.java
* @Package com.lotp.Test
* @Description: TODO(用一句话描述该文件做什么)
* @author no47wk lotp,Come back
* @date 2012-7-14 上午10:43:22
* @version V1.0
*/
package com.lotp.Test;
import java.util.HashMap;
import java.util.Iterator;
import android.app.Activity;
import android.os.Bundle;
import android.os.DropBoxManager.Entry;
import android.util.Log;
/**
* @ClassName: Test
* @Description: TODO(这里用一句话描述这个类的作用)
* @author no47wk lotp,Come back
* @date 2012-7-14 上午10:43:22
*/
public class Test extends Activity {
private HashMap<String, String> map;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
long start = System.currentTimeMillis();
map = getData();
KeySet();
EntrySet();
}
private void KeySet(){
Iterator<String> ite = map.keySet().iterator();
long start=System.currentTimeMillis();
while (ite.hasNext()) {
map.get(ite.next());
}
long end = System.currentTimeMillis();
Log.d("KeySet", end - start + " ");
}
private void EntrySet(){
Iterator<java.util.Map.Entry<String, String>> ite=map.entrySet().iterator();
java.util.Map.Entry<String, String> entry;
long start=System.currentTimeMillis();
while(ite.hasNext()){
entry=ite.next();
entry.getKey();
entry.getValue();
}
long end=System.currentTimeMillis();
Log.d("EntrySet", end-start+"");
}
private HashMap<String, String> getData() {
HashMap<String, String> ret = new HashMap<String, String>();
int i = 0;
while (i < 102400) {
ret.put(String.valueOf(i), "a");
i++;
}
return ret;
}
}