Java的map

 基本类型数据,直接用map.put(k,v)修改数据即可

 

hashMap无序,treeMap按key值的大小排序。

 

输出:

 

 

Iterate over the entrySet rather than the keySet. You get a set of Map.Entry<K, V> which have convenient getKey() and getValue() methods.

That said, Java's standard Map implementations have an implementation of toString() that does what you want. Of course, I reckon you'll only get points for reimplementing it, not for cleverly avoiding it...

for (Map.Entry<K, V> entry : myMap.entrySet()) {
     System.out.println("Key: " + entry.getKey() + ". Value: " + entry.getValue());
}
posted @ 2018-11-01 20:35  7894561230  阅读(137)  评论(0编辑  收藏  举报