java - 合并映射中键包含的值(Java)
问题描述
final Multimap<String, Map.Entry<Integer, Integer>>[] actionMap = new Multimap[]{null};
final boolean[] loaded = {false};
db.execute(connection -> {
PreparedStatement statement = null;
ResultSet resultSet = null;
actionMap[0] = ArrayListMultimap.create();
try {
statement = connection.prepareStatement("Blah Blah...
while (resultSet.next()) {
final String name = ...
actionMap[0].put(name, new AbstractMap.SimpleEntry<>(int1, int2));
我有一张地图,SimpleEntry
用于插入两个整数值(int1,int2)。在重复键上,我想合并已经映射的值。我的想法是computeIfPresent
,但我不知道 BiFunctions 因为我AbstractMap.SimpleEntry
用来输入两个值。任何帮助将非常感激。
解决方案
在放置和覆盖之前,检索现有值。
- 如果您得到 null,则没有这样的值,并且您按照最初的预期放置。
- 如果你得到一些东西,将你的新数据合并到一些东西中。
推荐阅读
- terminology - 用户实现方法的 API 术语
- c - 观察 PAPI 的 L1_MISS 本机事件计数器的意外结果
- azure - 通过 ARM 模板在 Azure Web App 中为容器启用持续部署
- magento-2.3 - 将 Magento-2.2.6 升级到 2.3.1
- c# - 如何使用实体框架核心调用没有主键的表
- node.js - 为什么当我使用模块 vue-template-compiler 加载站点时尝试渲染页面时出现错误?
- c# - 如果在 c# 中该类的任何方法中发生异常,则创建一个捕获异常的方法
- python-3.x - 使用python获取sharepoint页面
- ios - 移动设备上的 Azure App Service 身份验证问题
- javascript - 使用 Postman 时,我们可以像变量一样在 for 循环中增加全局变量名称吗