foreach not applicable to type 'java.util.Map<java.lang.String,java.lang.Object>'
时间: 2024-05-01 15:20:57 浏览: 282
在JSTL EL中处理java.util.Map,及嵌套List的情况
`foreach` is not applicable to `Map` in Java. However, you can iterate through the entries of a `Map` using a `for-each` loop like this:
```java
Map<String, Object> map = new HashMap<>();
// add some key-value pairs to the map
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
// do something with the key-value pair
}
```
In this example, the `entrySet()` method returns a `Set` of `Map.Entry` objects, which represent key-value pairs in the `Map`. The `for-each` loop iterates through this set, and for each entry, we can get the key and value using the `getKey()` and `getValue()` methods, respectively.
阅读全文