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 x
and y
with any number you like and you will produce a stream that has y
lots of the number x
.
You can obviously then call toArray
or do whatever operation you want.
IntStream.generate
creates an infinite stream using the supplier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With