공부

[kotlin] list to map

승가비 2022. 7. 9. 20:12
728x90
@Test
fun givenList_whenAssociatedBy_thenResult() {
    val myList = listOf(user1, user2, user3)
    val myMap = myList.associateBy({ it.name }, { it.hobbies })
    
    assertTrue(myMap.get("John")!!.contains("Hiking"))
}

https://www.baeldung.com/kotlin/list-to-map

 

Converting a List to Map in Kotlin | Baeldung on Kotlin

Learn how to convert a List to Map in Kotlin.

www.baeldung.com

 

728x90