Android

[Kotlin] HashMap

zerocool0713 2020. 12. 16. 00:43
반응형
fun main(args: Array<String>){  
  
    val hashMap:HashMap<Int,String> = HashMap<Int,String>() //define empty hashmap  
    hashMap.put(1,"Ajay")  
    hashMap.put(3,"Vijay")  
    hashMap.put(4,"Praveen")  
    hashMap.put(2,"Ajay")  
    println(".....traversing hashmap.......")  
    for(key in hashMap.keys){  
        println("Element at key $key = ${hashMap[key]}")  
    }
}  
Output:

.....traversing hashmap.......
Element at key 1 = Ajay
Element at key 2 = Ajay
Element at key 3 = Vijay
Element at key 4 = Praveen

 

ref : www.javatpoint.com/kotlin-hashmap

반응형