
在遍历过程中如果尝试修改正在被迭代的集合可能会抛出 ConcurrentModificationException 异常。因此,对于可变操作建议使用 Iterator 的 remove() 方法或者在Stream API中新建一个新的映射结构。
通义千问挺好用的
metricThresholdMap.setL7Threshold(metricThresholdMap.getL7Threshold()
.entrySet()
.stream()
collect(Collectors.toMap(entry -> this.snakeToCamel(entry.getKey()), // 新建映射关系时调用修改key的方法
Map.Entry::getValue, // 保留原有的value
(oldValue, newValue) -> oldValue, // 合并函数,这里假设不会有冲突的key,所以直接返回旧值
LinkedHashMap::new)));
浙公网安备 33010602011771号