How to create a map with key type point (x, y) and value type string in Kotlin

1 Answer

0 votes
fun main() {
    // Define Point as a data class
    data class Point(val x: Int, val y: Int)

    // Create a map with Point keys and String values
    val pointMap = mapOf(
        Point(2, 7) to "A",
        Point(3, 6) to "B",
        Point(0, 0) to "C"
    )

    // Print x and y separately
    for ((point, value) in pointMap) {
        println("x: ${point.x}, y: ${point.y} => $value")
    }
}


 
  
/*
run:

x: 2, y: 7 => A
x: 3, y: 6 => B
x: 0, y: 0 => C

*/

 



answered Aug 10 by avibootz
...