The following one-liner Java 8 version will generate [ 1, 2 ,3 ... 10 ]. The first arg of iterate
is the first nr in the sequence, and the first arg of limit
is the last number.
List<Integer> numbers = Stream.iterate(1, n -> n + 1)
.limit(10)
.collect(Collectors.toList());