package fanxijihe2;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class HashMapDemo2 {
public static void main(String[] orgs){
Map countries=new HashMap();
countries.put("CN", "中华人民共和国");
countries.put("RU", "俄罗斯联邦");
countries.put("FR", "法兰西共和国");
countries.put("US","美利坚合众国" );
String country=(String)countries.get("CN");
System.out.println("CN对应的国家是"+country);
System.out.println("Map中共有"+countries.size()+"个数据");
countries.remove("FR");
System.out.println("Map中包含FR的key吗?"+countries.containsKey("FR"));
System.out.println(countries.keySet());
System.out.println(countries.values());
System.out.println(countries);
Set keSet=countries.keySet();
Iterator<String> iterator=keySet.iterator();
while(iterator.hasNext()){
String key=(String)iterator.next();
System.out.println("关键字:\""+key+"\"映射的值是\""+countries.get(key)+"\"");
}
}
}
|