Map with Key as String and Value as List in Groovy

前端 未结 5 604
慢半拍i
慢半拍i 2021-02-03 18:54

Can anyone point me to an example of how to use a Map in Groovy which has a String as its key and a List as value?

5条回答
  •  不知归路
    2021-02-03 19:31

    Joseph forgot to add the value in his example with withDefault. Here is the code I ended up using:

    Map map = [:].withDefault { key -> return [] }
    listOfObjects.each { map.get(it.myKey).add(it.myValue) }
    

提交回复
热议问题