如何修改HashMap中元素的值

如何修改HashMap中元素的值,第1张

Map map=new HashMap()

map.put("测试",1)

map.put("测试2",2)

System.out.println(map.get("测试2"))

map.put("测试2",3)

System.out.println(map.get("测试2"))

输出结果是 : 2

3

1、用Object remove(Object key)方法从HashMap或者HashTable中移去待修改的key值对,该方法同时会返回该Key所对应的Object

2、用put(Object key, Object value) 将新的Key-Value重新放入HashMap(HashTable)

static String[] s1={"E","F","G","S","T","(",")","+","-","*","/","i","#"}

HashMap<String,List<String>>hashMap=new HashMap<String,List<String>>()

for(int i=5i<s1.lengthi++){

List list=new ArrayList()

list.add(s1[i])

hashMap.put(s1[i],list)

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/11321280.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存