HashMap泛型使用

package study;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class PropertyTest {
public static void main(String[] args) {
Map<Integer,String> map=new HashMap<Integer,String>();
map.put(1, "aa");
map.put(2, "bb");
map.put(3, "cc");
Set<Integer> set=map.keySet();
for(Iterator<Integer> iter=set.iterator();iter.hasNext();){
Integer key=iter.next();
String value=map.get(key);
System.out.println(key+"-->"+value);
}
System.out.println("-------------------");
Set<Map.Entry<Integer, String>> set2=map.entrySet();
for(Iterator<Map.Entry<Integer, String>> iter=set2.iterator();iter.hasNext();){
Map.Entry<Integer, String> entry=iter.next();
Integer key=entry.getKey();
String value=entry.getValue();
System.out.println(key+"--->"+value);
}
}
}

posted @ 2017-01-11 12:09  马云12314  阅读(4892)  评论(0编辑  收藏  举报