Java:列表中元素的数量 [英] Java: count of elements in a list
本文介绍了Java:列表中元素的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
如何计算列表中元素的出现
我有一个类似List<String> A={12, 12, 14, 16, 16}
的列表.我怎样才能清楚地找到元素的数量
12->2
14->1
16->2
通过使用countElements(A,"12")
或A.count("12")
之类的功能来
?是否有库或函数?
解决方案
您还可以使用方法How to count occurrence of an element in a List
I have a list like List<String> A={12, 12, 14, 16, 16}
. How can I find the number of elements distinctly as
12->2
14->1
16->2
by using a function like countElements(A,"12")
or A.count("12")
? Is there a library or a function?
解决方案
You can also utililize the method Collections.frequency
if you need the frequency of only some of the elements individually.
这篇关于Java:列表中元素的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文