EN
Java 8 - Int Stream API generate list with 10 random numbers
11 points
xxxxxxxxxx
1
int size = 10;
2
int min = 55;
3
int max = 123;
4
5
List<Integer> randList = new Random().ints(size, min, max)
6
.boxed().collect(Collectors.toList());
7
8
// [69, 93, 83, 61, 63, 62, 107, 82, 110, 103]
9
System.out.println(randList);
Above example uses IntStream.ints
with 3 args
xxxxxxxxxx
1
IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound)
Param description:
xxxxxxxxxx
1
streamSize the number of values to generate
2
randomNumberOrigin the origin (inclusive) of each random value
3
randomNumberBound the bound (exclusive) of each random value