Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,844 questions

51,765 answers

573 users

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, 2025 by avibootz

Related questions

3 answers 131 views
2 answers 56 views
1 answer 67 views
1 answer 68 views
3 answers 80 views
...