Java优化双重嵌套for循环

2022-11-03  本文已影响0人  云A00000
/**
     * 优化双重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));
    }
上一篇下一篇

猜你喜欢

热点阅读