Say I have two variables : a = 5
, b = 8
,
And I want :
Arrays.asList(5, 6, 7, 8)
How Can I Use Java stream To get this?
Say I have two variables : a = 5
, b = 8
,
And I want :
Arrays.asList(5, 6, 7, 8)
How Can I Use Java stream To get this?
you can use IntStream.rangeClosed to generate the numbers and collect into a list.
List<Integer> result = IntStream.rangeClosed(a, b)
.boxed()
.collect(Collectors.toList());