Collections: MutableList operations

 



// File:            Main.kt
// Programmer: Engineer Nolverto Urias Obeso
// Creation Date: 06/21/2023
// Email: nolvertou@gmail.com
// Description: Using MutableLists operations

fun main() {
val symptoms: MutableList<String> =
mutableListOf("white spots", "red spots", "not eating", "bloated", "belly up")
println(symptoms) // Output: [white spots, red spots, not eating, bloated, belly up]

symptoms.add("white fungus")
println(symptoms) // Output: [white spots, red spots, not eating, bloated, belly up, white fungus]

symptoms.remove("white fungus")
println(symptoms) // Output: [white spots, red spots, not eating, bloated, belly up]

println(symptoms.contains("red")) // Output: false
println(symptoms.contains("red spots")) // Output: true

println(symptoms.subList(3, symptoms.size)) // Output: [bloated, belly up]

println(listOf(1,5,3).sum()) // 9
println(listOf("a","b","ccc").sumOf { it.length }) // 5



}

Comments

Popular posts from this blog