

List on the other hand is represented by since there are no immutable collections equivalents available in Java. On the jvm level, Array is represented by arrays. It's also extended by to be used when a collection that allows for item modification is needed. Moreover Array is mutable whereas List is not.įurthermore is an interface implemented among others by. The major difference from usage side is that Arrays have a fixed size while (Mutable)List can adjust their size dynamically. Lists and other collections cannot be used in annotations.Īs to the usage, good practice is to prefer using lists over arrays everywhere except for performance critical parts of your code, the reasoning is the same to that for Java.

Arrays are also mapped, but they have other rules of Java interoperability.Ĭertain array types are used in annotations (primitive arrays, Array, and arrays with enum class entries), and there's a special array literal syntax for annotations. List and MutableList are mapped types and have special behaviour in Java interoperability (Java's List is seen from Kotlin as either List or MutableList). Lists in general do not have implementations optimized for primitives, though some libraries (outside JDK) provide primitive-optimized lists. which are mapped to Java primitive arrays ( int, double, char), not boxed ones ( Array is mapped to Java's Integer). val a: Array = Array(0) // won't compileĪrrays are optimized for primitives: there are separate IntArray, DoubleArray, CharArray etc. Println(a.size) // will always be 3 for this arrayĪrray is invariant on T ( Array is not Array), the same for MutableList, but List is covariant ( List is List).

As to the lists, MutableList has add and remove functions, so that it can increase and reduce its size. val a = arrayOf(1, 2, 3)Īrrays have fixed size and cannot expand or shrink retaining identity (you need to copy an array to resize it). val list1: List = LinkedList()Īrray is mutable (it can be changed through any reference to it), but List doesn't have modifying methods (it is either read-only view of MutableList or an immutable list implementation). indexing in a LinkedList goes through the links and takes O(n) time whereas ArrayList stores its items in a dynamically allocated array. Memory representation and operations logic of lists are defined in concrete implementation, e.g. List and MutableList are interfaces which have different implementations: ArrayList, LinkedList etc.

Arrays and lists (represented by List and its subtype MutableList) have many differences, here are the most significant ones:Īrray is a class with known implementation: it's a sequential fixed-size memory region storing the items (and on JVM it is represented by Java array).
