How to count duplicate elements in ArrayList?

前端 未结 10 1570
悲哀的现实
悲哀的现实 2020-12-15 11:55

I need to separate and count how many values in arraylist are the same and print them according to the number of occurrences.

I\'ve got an arraylist called digits :<

10条回答
  •  既然无缘
    2020-12-15 12:23

    List list = new ArrayList();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("a");
        list.add("a");
        list.add("a");
    
    int countA=Collections.frequency(list, "a");
    int countB=Collections.frequency(list, "b");
    int countC=Collections.frequency(list, "c");
    

提交回复
热议问题