I basically wanted to create 2D array whose size is known to me on runtime
I have declare and array of LongArray as below
private lateinit var optionalGroup: Array<LongArray>
And I can assign value to it as below where group is my Mutable Map
group.forEach { (key, value) -> optionalGroup[key - 1] = LongArray(value) }
My question is how can I initialize optionalGroup with size as of group ? I tried
`optionalGroup = Array(group.size)
thows error No value passed for parameter 'init'`
Array(group.size) { LongArray(0) }should work, but you will also overwrite all the values later. Consider using aMutableListinstead.