【发布时间】:2018-11-19 19:06:18
【问题描述】:
哪个是更快的流或每个循环,为什么?应该在什么场景下使用?
import java.util.*;
public class Ran {
public static void main(String[] args) {
// Get and shuffle the list of arguments
List<String> argList = Arrays.asList(args);
Collections.shuffle(argList);
// Print out the elements using JDK 8 Streams
argList.stream()
.forEach(e->System.out.format("%s ",e));
// Print out the elements using for-each
for (String arg: argList) {
System.out.format("%s ", arg);
}
System.out.println();
}
}
【问题讨论】:
-
流可能比较慢。
标签: java java-8 java-stream