Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

372
Views
¿Cómo iterar sobre hashmap en Kotlin?

¿Cómo iterar sobre HashMap en Kotlin ?

 typealias HashMap<K, V> = HashMap<K, V> (source)
over 4 years ago · Santiago Trujillo
4 answers
Answer question

0

Otra forma que no se ha mencionado es:

 val mapOfItems = hashMapOf(1 to "x", 2 to "y", -1 to "zz") mapOfItems.map { (key, value) -> println("$key = $value") }
over 4 years ago · Santiago Trujillo Report

0

Use 'for loop' o 'forEach' o 'Iterator'

 fun main(args : Array<String>) { val items = HashMap<String, String>() items["1"] = "USA" items["2"] = "Japan" items["3"] = "India" //for loop example println("\n-- Example 1.1 -- "); for ((k, v) in items) { println("$k = $v") } // forEach example println("\n-- Example 1.2 --"); items.forEach { (k, v) -> println("$k = $v") } //Iterator example println("\n-- Example 1.3 --"); val itr = items.keys.iterator() while (itr.hasNext()) { val key = itr.next() val value = items[key] println("${key}=$value") } }
over 4 years ago · Santiago Trujillo Report

0

No es tan difícil:

 for ((key, value) in map) { println("$key = $value") }

O
( Actualizado de acuerdo con la información de @RuckusT-Boom y @KenZira ).

 map.forEach { (key, value) -> println("$key = $value") }
over 4 years ago · Santiago Trujillo Report

0

Para la respuesta anterior, ¡tenga cuidado con Android debajo de N !

 map.forEach { key, value -> println("$key = $value") }

referencia a Java 8 api que conduce a:

 Rejecting re-init on previously-failed class java.lang.Class<T>

 map.forEach { (key, value) -> println("$key = $value") }

es la característica de Kotlin

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!