for (HashMap m : list) { boolean flag = false;//默认没有被引用 String bpId = (String) m.get("bpId"), ypId = (String) m.get("ypId"), xhId = (String) m.get("xhId"), hjsId = (String) m.get("hjsId"); if (bpId != null || ypId != null || xhId != null || hjsId != null) { flag = true; } map.put(m.get("id"), flag); }优化一下
时间: 2024-01-12 14:05:28 浏览: 92
Javapython for leetcode 1 array2 list3 string4 hashtable5 m.zip
可以尝试将 if 判断改为如下形式:
```java
if (m.containsKey("bpId") || m.containsKey("ypId") || m.containsKey("xhId") || m.containsKey("hjsId")) {
flag = true;
}
```
另外,在遍历 list 时,最好指定泛型类型,避免出现 unchecked 警告。完整代码如下:
```java
for (HashMap<String, Object> m : list) {
boolean flag = false; // 默认没有被引用
if (m.containsKey("bpId") || m.containsKey("ypId") || m.containsKey("xhId") || m.containsKey("hjsId")) {
flag = true;
}
map.put(m.get("id"), flag);
}
```
阅读全文