import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
*
* @author Administrator
*
*/
public class Test {
public static void main(String[] args){
//1、使用HashMap存储多组国家英文简称和中文全称的键值对
Map <String,String> countries=new HashMap<String,String>();
countries.put("CN", "中华人民共和国");
countries.put("RU", "俄罗斯联邦");
countries.put("FR", "法兰西共和国");
countries.put("US", "美利坚合众国");
//2、把键值放入一个集合当中
Set <String> sets = countries.keySet();
//3、利用迭代器输出各元素的key和value
Iterator <String> it = sets.iterator();
while (it.hasNext()) {
String key = it.next();
String value = countries.get(key);
System.out.println( "key是:" +key + "\tvalue是:" + value+ "\t");
}
}
}
|