V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
hastyfish
V2EX  ›  程序员

这段代码能不能抽象出来

  •  
  •   hastyfish · 2020-01-15 16:30:00 +08:00 · 1417 次点击
    这是一个创建于 1564 天前的主题,其中的信息可能已经有所发展或是发生改变。
            Set<String> mapKey = multipartFileMap.keySet();
            for (Apply apply : applys) {
                String i = apply.getApplyId().toString();
                if (!mapKey.contains(i)) {
                    multipartFileMap.put(i, null);
                }
            }
    

    主要是这个 String i = apply.getApplyId().toString(); 不知道怎么处理

    1 条回复    2020-01-15 16:40:19 +08:00
    lihongjie0209
        1
    lihongjie0209  
       2020-01-15 16:40:19 +08:00   ❤️ 2
    String i = apply.getApplyId().toString();
    if (!mapKey.contains(i)) {
    multipartFileMap.put(i, null);
    }



    可以使用 putIfAbsent

    multipartFileMap.putIfAbsent(apply.getApplyId().toString(), null)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   913 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:25 · PVG 06:25 · LAX 15:25 · JFK 18:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.