【发布时间】:2016-08-24 10:41:18
【问题描述】:
仅当键尚不存在时,我才需要将条目放入地图。对于 Java 8,我只使用 putIfAbsent,但我在 Java 7 中使用 Groovy。
说明问题的代码:
def map = [a: 1, b: 2, c: 3]
def newEntries = [a: 11, b: 22, d: 44]
def result = // put new entries to the map only if they are not present
assert result == [a: 1, b: 2, c: 3, d: 44]
是否可以使用一些 Groovy 功能来做到这一点,还是我需要手动完成?
【问题讨论】:
-
不,我不需要
Multimap,只需HashMap就可以解决我的问题
标签: dictionary groovy