Trying to declare an array of a certain size in Scala -


var arr = array[int](arr_size) println(arr_size + " " + arr.size) 

arr_size 30 arr.size 1? why this?

i trying declare empty array can fill in later @ designated indexes.

array[int](arr_size) creates array 1 element, arr_size, , commonly written array(arr_size), assuming arr_size type int.

use instead:

array.ofdim[int](arr_size).

you use more functional approach , fill array directly during initialization, e.g. array.tabulate.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -