I was a little suspicious about the stream performance, but thanks to a comment of Hulk, I realized that you need to warm up the lambda executions (run it at least twice) to get reasonable result.
public class StreamTest {
public static void main(String[] args) {
// will include lambda warm up time
java8test();
java8test();
java7test();
}
public static void java8test() {
List<String> test = new ArrayList<>();
test.add("--path=C:/log");
test.add("--time=hourly");
long start = System.nanoTime();
List<String> result = test.stream().flatMap(e->{
String[] array = e.split("=");
return Stream.of(array);
}).collect(Collectors.toList());
long end = System.nanoTime();
System.out.println("Java 8 style: " + (end-start) + "ns: " + result);
}
public static void java7test() {
String[] test2 = {"--path=C:/log", "--time=hourly"};
long start = System.nanoTime();
test2 = String.join("=", test2).split("=");
long end = System.nanoTime();
System.out.println("old style: " + (end-start) + "ns:" + Arrays.toString(test2));
}
}
Performance:
Java 8 style: 188154148ns: [--path, C:/log, --time, hourly]
Java 8 style: 129220ns: [--path, C:/log, --time, hourly]
old style: 364275ns:[--path, C:/log, --time, hourly]