This question already has an answer here:
- How do I fill arrays in Java? 8 answers
I know how to get an
int with a range of numbers:
int array = IntStream.of(0, 3).toArray();
But how can I get it with fixed length and one specific number?
IntStream.generate(() -> x).limit(y)
is what you need. Replace
y with any number you like and you will produce a stream that has
y lots of the number
You can obviously then call
toArray or do whatever operation you want.
IntStream.generate creates an infinite stream using the supplier.