我有大约30个HashMaps数据,我遇到了需要检查任何一个哈希图中是否存在某个值的情况。
例如
if (map1.contains(value)){ //remove the value with map1.remove() }
if (map2.contains(value)){ //remove the value with map2.remove() }
if (map3.contains(value)){ //remove the value with map3.remove() }
//and so on
我可以这样做30次,但我不确定它会有多高效,是否有更清洁的方法来做到这一点?任何帮助将不胜感激,谢谢。
答案 0 :(得分:2)
30地图很难,我不知道你的用例。
您可以将其保存在列表中并对其进行迭代,但您应该重构该类。
List<Map<String, Object>> testList = new ArrayList<>();
...//add maps
for(Map<String, Object> map : testList){
map.containsKey(...)
}