Search code examples
androidlistfirebasekotlinstringbuilder

Mutable list of data in Kotlin


Please how can I perform addition function with a mutable list of type Double in kotlin? I have a mutable list of numbers I get from Firebase
How can I write a function to Find the mathematical sum of the numbers in the list (Kotlin)?


Solution

  • you can reduce function to calculate the sum

    val list = mutablelistOf(1,2,3,4)
    
    val sum = list.reduce{ a,b ->
     return a + b
    }