public class Test10 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
HashMap<String, Integer>hm=new HashMap<>();
hm.put("强妹", 27);
hm.put("香香", 23);
hm.put("宗欣", 27);
hm.put("范雪峰", 20);
hm.put("林林", 23);
/*Set<Entry<String, Integer>>set=hm.entrySet();
for (Entry<String, Integer> en : set) {
System.out.println(en.getKey()+en.getValue());
}*/
/*Set<String>st=hm.keySet();
for (String string : st) {
}*/
/*Set<String>set=hm.keySet();
Iterator<String>it=set.iterator();
while(it.hasNext()){
String key=it.next();
Integer value=hm.get(key);
System.out.println(key+" "+value);
}*/
Set<Entry<String, Integer>>set=hm.entrySet();
Iterator<Entry<String, Integer>>it=set.iterator();
while(it.hasNext()){
Entry<String, Integer>en=it.next();
String key=en.getKey();
Integer value=en.getValue();
System.out.println(key+" "+value);
}
}
}
|
|