V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
hastyfish
V2EX  ›  程序员

这段代码能不能抽象出来

  •  
  •   hastyfish · Jan 15, 2020 · 1775 views
    This topic created in 2304 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   ·   4788 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 00:14 · PVG 08:14 · LAX 17:14 · JFK 20:14
    ♥ Do have faith in what you're doing.