The method get(int) in the type List<Map<String,Object>> is not applicable for the arguments (String)
时间: 2024-04-16 11:25:35 浏览: 272
This error occurs when you try to call the `get` method on a `List<Map<String, Object>>` object with a `String` argument. The `get` method in this context expects an integer argument, representing the index of the element you want to retrieve from the list.
To fix this error, you need to use an integer value instead of a string when calling the `get` method. For example, if you want to retrieve the element at index 0, you would call `get(0)` instead of `get("someKey")`.
相关问题
The method getOrDefault(Object, List<String>) in the type Map<Character,List<String>> is not applicable for the arguments (char, new HashSet<>())
这个错误是因为在使用 `getOrDefault()` 方法时,第二个参数的类型应该是 `List<String>`,但是你传递了一个 `HashSet<String>` 类型的对象。你可以将 `idiomSet` 的类型从 `HashSet<String>` 改为 `ArrayList<String>`,或者使用 `Collections.singleton(idiom)` 方法将成语转换为只包含一个元素的 Set,再将 Set 转换为 List,如下所示:
```java
List<String> idiomList = new ArrayList<>();
Map<Character, List<String>> idiomMap = new HashMap<>();
for (String idiom : idiomList) {
if (!idiom.isEmpty()) {
char lastChar = idiom.charAt(idiom.length() - 1);
List<String> idiomSet = idiomMap.getOrDefault(lastChar, new ArrayList<>());
idiomSet.addAll(Collections.singleton(idiom));
idiomMap.put(lastChar, idiomSet);
}
}
```
这样就可以解决这个错误了。
The method put(String, String) in the type Map<String,String> is not applicable for the arguments (String, int)
这个错误提示是因为你试图将一个整数类型的值传递给一个字符串类型的Map中。Map是一个键值对的集合,键和值必须具有相同的数据类型。如果你想将一个整数类型的值存储在Map中,你需要将它转换为字符串类型。你可以使用Integer.toString()方法将整数类型的值转换为字符串类型,然后将其传递给Map中的put()方法。例如:
```
Map<String, String> map = new HashMap<>();
int value = 123;
map.put("key", Integer.toString(value));
```
阅读全文