//利用键值对关系对象获取,错在哪儿了?
import java.util.*;
class MapDemo1{
public static void main(String[] args){
Map<String,Integer> m = new HashMap<String,Integer>();
m.put("abc",12);
m.put("abd",23);
m.put("cde",45);
System.out.println(m);
//运用entrySet获取Map.Entry<String,Integer>键值对
Set<Map.Entry<String,Integer>,Integer> set = m.entrySet();
//迭代
Iterator<Map.Entry<String,Integer>> it = set.iterator();
while(it.hasNext()){
Map.Entry me = it.next();
String s = me.getKey();
Integer i = me.getValue();
System.out.println(s+"="+i);
}
}
}
|
|