Lowercase all HashMap keys

前端 未结 4 1250
夕颜
夕颜 2021-02-12 14:17

I \'ve run into a scenario where I want to lowercase all the keys of a HashMap (don\'t ask why, I just have to do this). The HashMap has some millions of entries.

At fir

4条回答
  •  别那么骄傲
    2021-02-12 14:25

    Not sure about the memory footprint. If using Kotlin, you can try the following.

    val lowerCaseMap = myMap.mapKeys { it.key.toLowerCase() }
    

    https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/map-keys.html

提交回复
热议问题