find the frequency of elements in a java array

后端 未结 9 1521
灰色年华
灰色年华 2020-12-03 16:40

I have an int array:

{1,2,4,2,3,5,6,4,3}

How can I find frequencies of array elements like 1=1,2=2,3=2,4=4... I need a class w

9条回答
  •  失恋的感觉
    2020-12-03 17:16

    class MapTest
    {
        public static void main(String args[]){
            HashMap h = new HashMap();
            int arr[] = new int[]{2,2,3,3,5,6,7,9,9,0};
            for(int i=0; i

提交回复
热议问题