To create a new byte arrays in scala, you have two options.
To initialize it with data, you can do this:
val data = Array[Byte](10, -32, 17, 22)
If you want to initialize it to a specific length like a Java array, do this:
val length = 1000
Array.fill[Byte](length)(0)
Please remove the Array.fill example – I just tried it and performance is really bad! You should use:
new Array[Byte](length)
Thanks for the research. I was trying to use this to generate byte arrays for ND4S, so if you’re doing something like that, you can also initialize them from sequences, maybe that would perform better?
Actually, looks like ‘new Byte’ converts to Array.fill under the covers anyway 🙁