The most popular lists in Java are ArrayList
and LinkedList
.
In Kotlin I see ArrayList
and List
. Is List
actually a LinkedList
? For example
val list = listof("1st", "2nd")
Kotlin Topics. LinkedList provides a doubly linked list data structure implementation. It implements both the List and Deque interface. It belongs to the Java collections framework.
Linked lists differ from lists in the way that they store elements in memory. While lists use a contiguous memory block to store references to their data, linked lists store references as part of their own elements.
A list is an ordered collection of items. In Kotlin, lists can be either mutable ( MutableList ) or read-only ( List ). For list creation, use the standard library functions listOf() for read-only lists and mutableListOf() for mutable lists.
Queue is a collection of one or more elements arranged in memory in a contiguous fashion. A linked list is a collection of one or more elements arranged in memory in a dis-contiguous fashion. Static Queue is always fixed size. List size is never fixed.
Just tried printing the type,
val list = listOf("a")
println(list.javaClass)
output: class java.util.Collections$SingletonList
val list = listOf("a", "b", "c")
println(list.javaClass)
output: class java.util.Arrays$ArrayList
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With