• 请不要在回答技术问题时复制粘贴 AI 生成的内容
hastyfish
V2EX  ›  程序员

这段代码能不能抽象出来

  •  
  •   hastyfish · Jan 15, 2020 · 1821 views
    This topic created in 2327 days ago, the information mentioned may be changed or developed.
            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 replies    2020-01-15 16:40:19 +08:00
    lihongjie0209
        1
    lihongjie0209  
       Jan 15, 2020   ❤️ 2
    String i = apply.getApplyId().toString();
    if (!mapKey.contains(i)) {
    multipartFileMap.put(i, null);
    }



    可以使用 putIfAbsent

    multipartFileMap.putIfAbsent(apply.getApplyId().toString(), null)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   964 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 19:19 · PVG 03:19 · LAX 12:19 · JFK 15:19
    ♥ Do have faith in what you're doing.