Java Stream create from generator via method reference
import java.util.stream.Stream; public class Main { public static void main(String[] args) { Stream.generate(Main::next)/* ww w. jav a 2 s . c o m*/ .limit(10) .forEach(System.out::println); } static int i=0; private static int next(){ i++; return i; } }