Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

MutableList vs ArrayList

MutableList is ArrayList in Kotlin currently.

Create an Empty MutableList

Below is the most idiomatical way to create an empty mutable list in Kotlin.

[]

Another way to create an emtpy MutableList.

[]

Create an MutableList with Initial Values

Create a MutableList containing 3 zeros.

[0, 0, 0]

Create a MutableList with initial values.

[1, 2, 3]
[0, 1, 2, 3, 4, 5]
[0, 1, 2, 3, 4]
[1, 2, 3, 4]
3
0..3
Line_31.jupyter-kts (1:9 - 12) Unresolved reference: add
[1, 2, 3]
[1, 2, 3]
null

Verify that mList2 has the same elements as mList1.

true

Verify that mList2 is a different object than mList1.

false

Methods and Operators

addAll

[1, 2, 3]
[1, 2, 3, 4, 5, 6]
[2, 3]
[2, 3, 100]
[1, 2, 3, 100]
[1, 2]
[2, 3]
[2, 3, 1000, 2000]
[0, 1, 2]
[3, 4]

data class is preferred over Tuple-like data.

3.0