首页 > 编程语言 > 详细

Java的map

时间:2018-11-01 20:53:07      阅读:173      评论:0      收藏:0      [点我收藏+]

 基本类型数据,直接用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());
}

Java的map

原文:https://www.cnblogs.com/yizhaoAI/p/9892315.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!