Hey guys. Is there any function that works as addAll but allows you to specify the index for the collection to be paste?
Thanks
1 Like
Collection
s don’t have any concept of an index, in general, for example Set
is a collection but it doesn’t have any “index” nor you can decide “where” to add something to a Set
.
Specific collections might have indices for their elements, like List
s.
In fact, list has a version of addAll
which does what you ask:
addAll - Kotlin Programming Language.
2 Likes
Yes, There is a function called copyOfRange.
Example:
val telephoneNumbers = arrayOf(“(950) 381-9089”, “(727) 812-4646”, “(977) 233-7761”, “(447) 873-4959”)
val copy = telephoneNumbers.copyOfRange(1, 4)