kotlin collection literals code example
Example: kotlin collection literals
listOf(1,2,3,4) // List<Int>
mutableListOf(1,2,3,4) // MutableList<Int>
setOf("A", "B", "C") // Set<String>
mutableSetOf("A", "B", "C") // MutableSet<String>
arrayOf('a', 'b', 'c') // Array<Char>
mapOf(1 to "A", 2 to "B") // Map<Int, String>
mutableMapOf(1 to "A", 2 to "B")
// MutableMap<Int, String>
sequenceOf(4,3,2,1) // Sequence<Int>
1 to "A" // Pair<Int, String>
List(4) { it * 2 } // List<Int>
generateSequence(4) { it + 2 } // Sequence<Int>