Kotlin: Collection Literals

listOf(1,2,3,4) – List

mutableListOf(1,2,3,4) – MutableList

setOf("A", "B", "C") – Set

mutableSetOf("A", "B", "C") – MutableSet

arrayOf('a', 'b', 'c') – Array

mapOf(1 to "A", 2 to "B") – Map

mutableMapOf(1 to "A", 2 to "B") – MutableMap

sequenceOf(4,3,2,1) – Sequence

1 to "A" – Pair

List(4) { it * 2 } – List

generateSequence(4) { it + 2 } – Sequence

Leave a Reply

Your email address will not be published. Required fields are marked *