美文网首页
Java优化双重嵌套for循环

Java优化双重嵌套for循环

作者: 云A00000 | 来源:发表于2022-11-03 11:24 被阅读0次
    /**
         * 优化双重for循环
         * */
        public static void traditionFor2(List<Wupin> wupinList, List<Order> orderList) throws InterruptedException {
            int count = 0;
            Long startTime =System.currentTimeMillis();
            System.out.println("当前时间:"+startTime);
            //集合转map
           val s=  wupinList.stream().collect(Collectors.toMap(Wupin::getOrderId, Wupin->Wupin));
            for (Order order:orderList) {
                val wuping = s.get(order.getOrderId());
                Thread.sleep(1);
                if (wuping != null){
                    order.setWupingName(wuping.getWupingName());
                    count++;
                }
            }
            Long endTime =System.currentTimeMillis();
            System.out.println("结束时间:"+endTime);
            System.out.println("循环次数:"+count);
            System.out.println(JSONUtil.toJsonStr(orderList));
        }
    

    相关文章

      网友评论

          本文标题:Java优化双重嵌套for循环

          本文链接:https://www.haomeiwen.com/subject/ehxetdtx.html