Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scala 2.11.8 how to fill an array

I want to create an array that contains the same value repeated for a very large number of times, say 1,000,000.

I was thinking to use something like Array.fill(1000000)(0). However, after reading the documentation for Scala 2.11.8, I found that there is no such members of Array in this version.

Is there any other ways that can create the array without using loop? Thanks in advance for your help.

like image 911
J. zhao Avatar asked Dec 08 '25 08:12

J. zhao


1 Answers

This will do the trick:

Array.fill[Int](1000000)(0)

Read more here: https://alvinalexander.com/scala/scala-list-class-examples

like image 178
Sohum Sachdev Avatar answered Dec 09 '25 22:12

Sohum Sachdev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!