Is this how I initialize a list with values in Kotlin?
I want to store a number of counts per value, something like this:
value count
0 -> 6
1 -> 2
2 -> 0
3 -> 7
As shown in the example, the values start at 0 and are consecutive integers.
I want to initialize all counts with 0, so that I can then increment them.
This is what I came up with:
val histogram = Array(numBuckets) { 0 }.toMutableList() as ArrayList
histogram[2]++
It works, but the initialization feels a bit convoluted. Is there a better way? Is the ArrayList the correct collection...