本帖最后由 明月几时有 于 2013-11-15 01:14 编辑
package cn.itcast.eclipse;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class Demo2 {
/**
* @param args
*/
public static void main(String[] args) {
Map<String, String>hs=new HashMap<String,String>();
hs.put("01", "zhangsan");
hs.put("02", "lisi");
hs.put("03", "wangwu");
Set<Map.Entry<String, String>> s=hs.entrySet();
Iterator<Map.Entry<String, String>>it=s.iterator();
while(it.hasNext()){
Map.Entry<String, String> me=it.next();
String key=me.getKey();
String value=me.getValue();
//String key=it.next().getKey();//把上面三句代码简写成这两句,运行会出异常,不解,求指点!
//String value=it.next().getValue();
System.out.println(key+" : "+value);
}
}
}
|