1

I have an array of integers (val arr = intArrayof(6, 8, 11, 13)) and I want to set the values of the second and third elements equal to the values of another IntArray (val arr2 = intArrayOf(4, 7)),how do I do that?

I know I can set the values individually using the set method (arr.set(1, 4)) or with the index notation (arr[2] = 7) but is there a way to do it with a whole array/slice?

With Python I simply used slice notation, but that doesn't seem to work. Thank you

1 Answer 1

1

Use copyInto:

val arr = intArrayOf(6, 8, 11, 13) val arr2 = intArrayOf(4, 7) arr2.copyInto(arr, /* offset into arr */ 1) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.