val list = listOf(1, 2, 3, 4, 5)
val mutableList = mutableListOf(1, 2, 3)
mutableList.add(4)
mutableList.removeAt(0)
val first = list[0]
val last = list.last()
val set = setOf(1, 2, 3, 2)
val mutableSet = mutableSetOf(1, 2, 3)
mutableSet.add(4)
mutableSet.remove(1)
val map = mapOf("a" to 1, "b" to 2, "c" to 3)
val mutableMap = mutableMapOf("a" to 1)
mutableMap["b"] = 2
mutableMap.remove("a")
val value = map["a"]
val valueOrDefault = map.getOrDefault("d", 0)
val numbers = listOf(1, 2, 3, 4, 5)
val doubled = numbers.map { it * 2 }
val nested = listOf(listOf(1, 2), listOf(3, 4))
val flattened = nested.flatMap { it }
val strings = listOf("1", "2", "a", "3")
val ints = strings.mapNotNull { it.toIntOrNull() }
val numbers = listOf(1, 2, 3, 4, 5)
val evens = numbers.filter { it % 2 == 0 }
val odds = numbers.filterNot { it % 2 == 0 }
val filtered = numbers.filterIndexed { index, value ->
index % 2 == 0
}
val numbers = listOf(1, 2, 3, 4, 5)
val sum = numbers.sum()
val avg = numbers.average()
val max = numbers.maxOrNull()
val min = numbers.minOrNull()
val product = numbers.reduce { acc, i -> acc * i }
val result = numbers.fold(10) { acc, i -> acc + i }
val words = listOf("apple", "banana", "apricot", "berry")
val grouped = words.groupBy { it.first() }
val (short, long) = words.partition { it.length < 6 }
val numbers = listOf(3, 1, 4, 1, 5, 9)
val sorted = numbers.sorted()
val desc = numbers.sortedDescending()
val words = listOf("banana", "apple", "cherry")
val byLength = words.sortedBy { it.length }
val sequence = sequenceOf(1, 2, 3, 4, 5)
.filter { it % 2 == 0 }
.map { it * 2 }
.toList()
val seq = listOf(1, 2, 3).asSequence()