旅游景点 旅游攻略 日本旅游 文化旅游 旅游景区 昆明旅游 桂林旅游 乡村旅游 上海旅游

java8新特性:并行流与顺序流

时间:2024-10-12 22:11:57

1、使用顺序流计算0到1亿之和:@Testpublic void test10() { Instant start = Instant.荏鱿胫协now(); LongStream.rangeClosed(1,10000000000000L).reduce(0,Long::sum); System.out.println("系统执行时间:"+Duration.between(start,Instant.now()).toMillis()); }

java8新特性:并行流与顺序流

3、使用并行流计算0到1亿之和:@Test public void test11() { Instant start = 朐袁噙岿Instant.now(); LongStream.rangeClosed(1,10000000000000L).parallel().reduce(0,Long::sum); System.out.println("系统执行时间:"+Duration.between(start,Instant.now()).toMillis()); }

java8新特性:并行流与顺序流

5、并行流计算集合数量public void test12() { System.out.println(deptList.stream().parallel().count()); }

java8新特性:并行流与顺序流
© 途途旅游