/**
* 优化双重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));
}
网友评论