How to count the number of occurrences of an element in a List

后端 未结 22 1493
一生所求
一生所求 2020-11-22 12:25

I have an ArrayList, a Collection class of Java, as follows:

ArrayList animals = new ArrayList();
animals.add(\"bat\         


        
22条回答
  •  一整个雨季
    2020-11-22 12:51

    There is no native method in Java to do that for you. However, you can use IterableUtils#countMatches() from Apache Commons-Collections to do it for you.

提交回复
热议问题