What is the difference between List and Array in Kotlin? When to use which?
Hello colleagues! I just started learning Kotlin and switched from Java. Kotlin has two similar types: `List` and `Array`. I see that both store multiple elements, but I can't understand the key difference and when to use which.
For example, I'm writing a simple program to store student names:
```kotlin
val namesArray = arrayOf("Alice", "Bob", "Charlie")
val namesList = listOf("Alice", "Bob", "Charlie")
```
Both work, I can access by index: `namesArray[0]` and `namesList[0]` — both return "Alice". But I noticed that `Array` has a `size` property, while `List` has `count()`. Also, I can change an array element:
```kotlin
namesArray[0] = "Eve" // works
namesList[0] = "Eve" // compilation error
```
Why is that? Also I heard that `List` can be mutable (`Muta
No answers yet.
Log in to leave an answer