How to initialize an array in Kotlin with values?
How to initialize an array in Kotlin with values?
Here are a few ways to initialize an array with values in Kotlin:
val numbers = arrayOf(1, 2, 3, 4, 5)
This creates an array of integers with the specified values.
val numbers = Array(5) { i -> (i + 1) * 10 }
This creates an array of size 5 and initializes each element using a lambda expression. The lambda takes the index i and returns (i + 1) * 10, which will result in the values ``.
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.