/**
* 优化双重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循环
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 前言 Google Play应用市场对于应用的targetSdkVersion有了更为严格的要求。从 2018 年...