且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在HashMap中一次更新所有值

更新时间:2023-01-08 10:12:22

map.put(entry.getKey() ,MY_VALUE);
}
}


I have a HashMap with some Keys - Values.

On some condition I want to update all values to single value regardless of keys.

Is there any util or predefined methods to do this, without for loop?

Any suggestions?

if (yourCondition) { 
      for (Map.Entry<String, String> entry : map.entrySet()) {
          map.put(entry.getKey(), MY_VALUE);
      }
}