import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class Test {
public static void main(String args[]){
HashMap map = new HashMap();
map.put("1", "001");
map.put("2", "002");
map.put("3", "003");
map.put("4", "004");
map.put("5", "005");
map.put("6", "006");
System.out.println(map.get("5"));
System.out.println(map.size());
方法1:效率更高
Iterator iterator = map.entrySet().iterator();
while(iterator.hasNext()){
Map.Entry entry = (Map.Entry) iterator.next();
Object key = entry.getKey();
System.out.println(key);
System.out.println(entry.getValue());
}
方法2:
Iterator iter = map.keySet().iterator();
while (iter.hasNext()) {
Object key = iter.next();
Object val = map.get(key);
}
}
阅读(1998) | 评论(0) | 转发(0) |