val immutableList = listOf(1, 2, 3) val immutableSet = setOf("a", "b", "c") val immutableMap = mapOf("key1" to "value1", "key2" to "value2") fun List<Int>.sum(): Int { var result = 0 for (item in this) { result += item } return result } val list = listOf(1, 2, 3) val sum = list.sum() val list = listOf(1, 2, 3, 4, 5) val evenNumbers = list.filter { it % 2 == 0 } val doubledNumbers = list.map { it * 2 } val sum = list.reduce { acc, i -> acc + i } val str = "Hello, World!" val parts = str.split(",") val upperCase = str.toUpperCase() val str = "Hello, World!" val replacedStr = str.replace(Regex("[aeiou]"), "*") val file = File("path/to/file.txt") val lines = file.readLines() file.writeText("Hello, World!")


上一篇:
下一篇:
切换中文