kotlinmutablelistlistof

How could I add a list of People in Kotlin?


I'm trying to create a list of people with name and characteristic. How could I do this?

class Player(val name: String, val nachname: String, val nr: Int)

// And I'm trying to do this:

fun main() {
    val team2 = mutableListOf<Player>()
    team2.add("Max", "Mustermann", 12)
 
    println("${team2.size}")
}

Solution

  • You're looking for

    team2.add(Player("Max", "Mustermann",12))