I was going through some Kotlin basics and found two syntaxes.
ArrayList()
And
arrayListOf()
>
When creating an empty array, you can use either:
val emptyArray1 = ArrayList()
val emptyArray2 = arrayListOf()
But when creating an array from existing elements, you have to use one or the other depending on whether the existing elements are already in a collection or you want to specify them individually:
val arrayFromCollection = ArrayListOf(hashMap.keys)
val arrayFromElements = arrayListOf("1", "2", "3")
Note that you can use the spread operator to pass an existing collection into arrayListOf as individual elements, but if the collection is anything other than another array, you also need to convert it to an array. This probably isn't worth the extra verbosity:
val arrayFromCollectionVerbose = arrayListOf(*hashMap.keys.toTypedArray())