Jee*_*evi 1 collections groovy map
我有一张类似的地图。
xxx-10.name ='welcome'
xxx-10.age ='12'
xxx-10.std ='2nd'
xxx-12.name ='welcome'
xxx-12.age ='12'
xxx-12.std ='2nd'
yyy-10.name ='welcome'
yyy-10.age ='12'
yyy-10.std ='2nd'
yyy-12.name ='welcome'
yyy-12.age ='12'
yyy-12.std ='2nd'
Run Code Online (Sandbox Code Playgroud)
wen 用户给出 xxx 我必须返回包含所有 xxx 条目的子图,而不管与之关联的数字是多少。有没有办法使用正则表达式来实现这一目标?或者没有迭代键?
我可以使用该实用程序获得子地图..
groovy 中有一个用于集合的过滤功能。见API
def result = [a:1, b:2, c:4, d:5].findAll { it.value % 2 == 0 }
assert result.every { it instanceof Map.Entry }
assert result*.key == ["b", "c"]
assert result*.value == [2, 4]
Run Code Online (Sandbox Code Playgroud)
在您搜索yourSearchString使用String.startsWith() 时的情况:
map.findAll { it.key.startsWith(yourSearchString) }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2578 次 |
| 最近记录: |