Counting in an ArrayList - Java

后端 未结 1 1949
粉色の甜心
粉色の甜心 2021-01-25 21:19

UPDATED CODE

I\'m trying to figure out a way to count how often one value appears in an ArrayList.

System.out.println(\"Hand 1,         


        
相关标签:
1条回答
  • 2021-01-25 21:58

    Collections.frequency

    You have this feature already available from Collections class, in the frequency method.

    public static int frequency(Collection<?> c, Object o)
    

    That will return the number of occurrences of a specific object inside a collection.

    Mind that without providing a vaild equals method this won't work or at least won't work with the equality you have in mind, since Java does't know your meaning of equality.

    0 讨论(0)
提交回复
热议问题