IntStream iterate function with filter
问题 I was reading this book called Modern Java in Action and one part of code I could not comprehend. IntStream.iterate(0, n -> n + 4) .filter(n -> n < 100) .forEach(System.out::println); Authors says that code will not terminate. The reason is that there’s no way to know in the filter that the numbers continue to increase, so it keeps on filtering them infinitely! I did not get the reason. Could someone explain it why. 回答1: You can find the answer in javadocs of IntStream#iterate : Returns an