Map<Integer, String> map = new HashMap<Integer, String>();
map.put(1, "a");
map.put(2, "b");
map.put(3, "ab");
map.put(4, "ab");
map.put(4, "abc");
1、
for(Integer in:map.keySet()) {
String s = map.get(in);
System.out.println(s);
}
2、使用迭代器
Iterator<Entry<Integer, String>> iterator = map.entrySet().iterator();
while(iterator.hasNext()) {
Entry<Integer, String> entry = iterator.next();
System.out.println(entry.getKey());
}
3、适合大数据量
for (Entry<Integer, String> e : map.entrySet()) {
System.out.println(e.getValue());
}
4、顺序读取map的值
for (String v : map.values()) {
System.out.println(v);
}