public static void DemoMap(){
Map<String, String> map = new HashMap<String, String>();
// 添加元素
map.put("Mon", "星期一");
map.put("Tues", "星期二");
map.put("Wed", "星期三");
map.put("Thur", "星期四");
map.put("Fir", "星期五");
map.put("Sat", "星期六");
map.put("Sun", "星期日");
// 通过keySet方法获取所有键值
Set<String> keySet = map.keySet();
for (String key : keySet) {
String value = map.get( key);
System.out.println("value:" + value);
}
// 通过entrySet方法获取所有键值
Set<Map.Entry<String, String>> entrySet = map.entrySet();
for (Entry<String, String> entry : entrySet) {
String entryKey = entry.getKey();
String entryValue = entry.getValue();
System.out.println("entryValue:" + entryValue);
}
Iterator<String> iterator = map.keySet().iterator();
while(iterator.hasNext()){
String key = iterator.next();
System.out.println(key+":"+map.get(key));
}
}
参考链接:http://blog.csdn.net/hello_zhou/article/details/51583526