In Java byte[] st = new byte[4096]
, implies that size of array st
will not exceed 4096 bytes.
The Scala equivalent is st:Array[byte] = Array()
where size is unknown. If I am reading a huge file into this array, then how can I limit the size of the array?
Will there be any side effect if I don't care about the size for the above operation?
The Scala Array is an interesting creature: It's mutable in that its elements can be changed, but it's immutable in that its size cannot be changed.
Reduce Array Size to The Half in C++ We can choose a set of integers and remove all the occurrences of these integers in the array. We have to find the minimum size of the set so that at least half of the integers of the array are removed. So for example, if arr = [3,3,3,3,5,5,5,2,2,7], then the output will be 2.
The theoretical maximum Java array size is 2,147,483,647 elements. To find the size of a Java array, query an array's length property.
Tuple are of type Tuple1 , Tuple2 ,Tuple3 and so on. There is an upper limit of 22 for the element in the tuple in the scala, if you need more elements, then you can use a collection, not a tuple.
var buffer = new Array[Byte](4 * 1024)
Works just fine, and it behaves as expected.
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