java - Update the Key of a Map
问题描述
I have a Linked Hash Map as follows :
Map <Object, Object> test ;
With:
The keys are Strings with 4 chars max , like this :
1234 -> value1
2 -> value2
342 -> value3
40 -> value4
And I want to update the values of the keys filling the ones that has less than 4 chars , with zeros '0'. For example :
1234 -> value1
2000-> value2
3420 -> value 3
4000 -> value 4
I've tried
test.forEach((key, value) -> {
Object storedValue = value;
Object normalizedKey = StringUtils.rightPad(key.toString(),4,'0');
test.remove(key);
test.put(normalizedKey,storedValue);
});
But its giving me ConcurrentMOdificationException.
How can I achieve my goal ?
解决方案
推荐阅读
- r - ggplot2 或 plotly 中带有水平条形图的表格
- excel - 自动过滤excel VBA中的多列
- c - 如何在回调函数中不使用 pcap_breakloop() 从 pcap_loop() 或 pcap_dispatch() 返回
- c# - EF Core 迁移为一对多关系添加了错误方向的删除级联
- r - 如何用 BBsolve 求解非线性
- php - Zend Framework 使用内置 PHP 服务器?
- javascript - 无法让 react-grid-gallery 显示本地图像
- ruby-on-rails - 如何为远程数据库运行 Rails CLI 命令?
- wordpress - Wordpress - 是否可以从页面 html 块向 wordpress 数据库发出请求?
- c - 打印字符串的中间字符