收集器Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)返回一个未指定的映射类型,它甚至可能是不可变的(尽管它是HashMap在当前版本中)。如果您想保证返回HashMap实例,则必须改用Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1,v2)->{throw new IllegalArgumentException("duplicate ...
这为我修好了: JsonArray jsoncargo = jsonObject.getJsonArray("cargo"); Map<String, Integer> cargo = new HashMap<>(); for (int i = 0; i < jsoncargo.size(); i++) { String type = jsoncargo.getJsonObject(i).getString("type"); Integer amount = jsoncargo.getJsonObject(i).getInt...