我想获得所有数字及其发生次数的计数。
像1 = 4,2 = 3等
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
}
}
关于grails - 如何找到grails中每个元素的出现次数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38145337/