package day200802;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class MapDemo {
public static void main(String[] args) {
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("a", 1);
map.put("b", 2);
map.put("c", 3);
//通过keyset来迭代
// Set<String> set = map.keySet();
// //通过getClass打印类型
// System.out.println(set.getClass());//class java.util.HashMap$KeySet
// HashMap的内部类
//
// Iterator<String> it = set.iterator();
// while (it.hasNext()) {
// String key = it.next();
// System.out.println(map.get(key));
//
// }
//
// System.out.println("---------------------");
// for (String s : set) {
// System.out.println(map.get(s));
// }
//通过entrySet来迭代
Set<Entry<String, Integer>> set = map.entrySet();
Iterator<Entry<String, Integer>> it = set.iterator();
while (it.hasNext()) {
Entry<String, Integer> entry = it.next();
System.out.println(entry.getKey() + "---" + entry.getValue());
}
System.out.println("-----------------------");
for (Entry<String, Integer> entry : set) {
System.out.println(entry.getKey() + "---" + entry.getValue());
}
}
}