0

I am studying the codelab on Kotlin collections from the Android team.

I am surprised that they show no syntax for creating arbitrary size collections, only syntaxes such as:

arr=arrayof{0,1,2,3}
list= listof{0,1,2,3}

and nothing like

arr= [0,0,0,....,0] (with size N)

where N is some integer, which you can do in most languages, or for maps for example something like

mmap = mapOf (key -> someFunctionOfKey(key)) for keys in a certain range

How can I do this for arrays, lists, maps, sets, etc...? I couldn't find the syntax on the internet.

DarkBulle
  • 125
  • 3
  • 1
    What does it mean that it is empty and has some size at the same time? It sounds contradicting. Do you mean to fill it initially with nulls? Or to preallocate the space for a growable collection to avoid copying the data at a later time? – broot Aug 26 '23 at 19:36
  • @broot I have edited my question, you're right – DarkBulle Aug 26 '23 at 19:56
  • 1
    So what's the difference between `arr=arrayof{0,0, ..., 0}` and `arr = [0,0,0, ..., 0]`, ie what could you do with the latter, what you can't do with the prior? – derpirscher Aug 26 '23 at 20:00
  • @derpischer, I want an array of 1000 "0", I am not gonna type them ? – DarkBulle Aug 26 '23 at 20:02

0 Answers0