Lists
Lists are collections of indexed items. Lists support insertion and retrieval of items by their position. Besides the ArrayListclass, which is probably the most used implementation, the List interface is also implemented in the LinkedList class. The ArrayList class is usually the one you'll use because it offers retrieval of items by position in constant time, and doesn't have the memory overhead of an additional Node object for each item which the LinkedList has. The Kotlin library provides several methods for creating instances of List interfaces. You can create the immutable instance of a List by calling the listOf function. The function accepts a vararg parameter which can be used to initialize the list with items:
val superHeros ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access