We would like to know how to use Stream.iterate to create long list.
import java.util.stream.Stream; public class Main { public static void main(String...args){ long l = Stream.iterate(1L, i -> i + 1).limit(3).reduce(Long::sum).get(); System.out.println(l); } }
The code above generates the following result.