converting for loop to java 8 stream
问题 I was playing around with Java 8. I had some trouble converting this for loop into Java 8 Stream. for (int y = 0; y < 5; y ++) { for (int x = y; x < 10; x += 2) { System.out.println(x+y); } } Please help! 回答1: The canonical way of converting nested loops is to use flatMap on a stream, e.g. IntStream.range(0, 5).flatMap(i->IntStream.range(i, 10)) .forEach(System.out::println); The tricky part on your task is the increment by two as this has no direct equivalent in the stream API. There are two