I thought that only affects whether or not you can...
# getting-started
h
I thought that only affects whether or not you can expand or contract the size of the list
r
You're thinking Array vs List, not List vs MutableList
h
well MutableList == ArrayList, whereas I honestly don't really know the functional difference between Array and List
r
Array is a specific data structure in memory, whereas List is an interface. ArrayList is a List backed by an Array, but you can have Lists backed by other mechanisms, such as LinkedList.
h
In java, i only ever used
List
as an type, but in kotlin i use it in the same way i'd use java arrays
am i misusing things?
kotlin list != java list, yeah?
r
Good rule of thumb is always use a List unless you specifically need an Array (if you're not sure, you probably don't need an array). Note that ArrayList is a List, not an Array (it just uses an array internally).
Ultimately Kotlin Lists and Java Lists are the same (on the JVM of course), but they have a slightly different interface. Java assumes all Lists are mutable, whereas Kotlin does not, and instead distinguishes between List and MutableList. In Java, if you create an immutable list, it will just be a List with all the mutating functions throwing exceptions.
Basically (assuming you have an immutable list), in Java
list.add(...)
throws an exception, whereas in Kotlin
list.add(...)
doesn't exist.
h
thank you!
r
Sure thing