Which is faster stream or for each loop and why? which should be used in which scenario?
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();
}
}