首页
IT
登录
6mi
u
盘
搜
搜 索
IT
在java的Map集合中,怎样更改value的值
在java的Map集合中,怎样更改value的值
xiaoxiao
2022-06-30
44
在java的Map集合中,怎样更改value的值
报果
|
浏览 1038 次
2015-11-28 15:17
2015-11-28 15:23
#团队夺宝战,快来开启本次夺宝之旅吧!#
最佳答案
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import java.util.HashMap; import java.util.Map; public class Demo { public static void main(String[] args) { Map<Integer,Integer> m = new HashMap<Integer,Integer>(); m.put( 1 , 1 ); print(m); m.put( 1 , 2 ); print(m); } private static void print(Map<Integer, Integer> m) { for (Map.Entry<Integer, Integer> mm : m.entrySet()) System.out.println( "K: " +mm.getKey()+ ",V: " +mm.getValue()); } } //供参考,重新放一个相同的key,会自动覆盖value的。
本回答由提问者推荐
转载请注明原文地址: https://ju.6miu.com/read-1125632.html
专利
最新回复
(
0
)