Hey guys. Is there any function that works as addAll but allows you to specify the index for the collection to be paste?

1 Like

Collections 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 Lists.
In fact, list has a version of addAll which does what you ask:,the%20result%20of%20the%20operation.


Yes, There is a function called copyOfRange.

val telephoneNumbers = arrayOf("(950) 381-9089", “(727) 812-4646”, “(977) 233-7761”, “(447) 873-4959”)
val copy = telephoneNumbers.copyOfRange(1, 4)