0
私はすべての数字とその出現の数を取得したい。 1 = 4,2 = 3のような
などgrailsの各要素のオカレンス数を調べる方法は?
def list=[1,1,1,2,1,2,3,2,3,4,9,4,6,3,6]
私はすべての数字とその出現の数を取得したい。 1 = 4,2 = 3のような
などgrailsの各要素のオカレンス数を調べる方法は?
def list=[1,1,1,2,1,2,3,2,3,4,9,4,6,3,6]
def list=[1,1,1,2,2,2,3,3,1,6,4,6,5,4]
def countMap=[:]
list.each{
if(countMap[it]){
countMap[it]=countMap[it]+1
}else{
countMap[it]=1
}
}
assert list.countBy { it } == [1:4, 2:3, 3:3, 4:2, 9:1, 6:2]
list.count(値)があなたを行う必要があります。http://mrhaki.blogspot.de/2009/12/groovy- goodness-counting-items-in-list.html – LordWilmore